Page MenuHomePhabricator

VisualEditor: Clean up constructor params to dm.Node subclasses
Closed, ResolvedPublic

Description

  • dm.LeafNode has (length, element), where length is ignored and forced to 0 by all subclasses except for dm.TextNode
  • dm.BranchNode has (children, element), length is computed while children are added

The code in dm.Document constructing node trees needs to be aware of this, but at the same time it doesn't even use these parameters, because branch nodes are created as childless nodes that have their children added later, and text nodes are created with length zero and have the correct length set later. So we should just get rid of these parameters and make the constructors take a single element parameter, that would get them in line with other dm.Model subclasses (dm.Annotation and dm.MetaItem) as well.

While we're at it, we should also fix the documentation that claims that the element parameter is optional, it really isn't.


Version: unspecified
Severity: enhancement

Details

Reference
bz55871

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 2:15 AM
bzimport set Reference to bz55871.

(In reply to comment #0)

While we're at it, we should also fix the documentation that claims that the
element parameter is optional, it really isn't.

It is in fact optional. The lowest class (ve.dm.Model) has:

element || { 'type': this.constructor.static.name }