Opened 10 years ago

Closed 9 years ago

#10100 closed task (wontfix)

Tree code minor simplification

Reported by: Les Owned by:
Priority: low Milestone: 1.6
Component: Dijit Version: 1.4.0b
Keywords: Tree Cc: bill
Blocked By: Blocking:

Description

I found some Tree code that can be simplified :)

// Current code
this.getChildren().forEach(function(child){
	dijit._Container.prototype.removeChild.call(this, child);
}, this);

// New code
this.getChildren().forEach(dijit._Container.prototype.removeChild);

// Current code
dojo.forEach(this.getChildren(), function(child, idx){
  child._updateLayout();
});

// New code (removed unused local var idx)
dojo.forEach(this.getChildren(), function(child){
  child._updateLayout();
});

Change History (5)

comment:1 Changed 10 years ago by Les

I see code in a few place that could be tiny bit shorter. It doesn't amount to much, but the code will be smaller.

dojo.forEach(this.getChildren(), function(child){
	child.attr("indent", indent+1);
});

this.getChildren().forEach(function(child){
	child.attr("indent", indent+1);
});

comment:2 Changed 10 years ago by bill

As discussed in #9985 we can't in general depend on getChildren() returning a NodeList rather than a simple array. I guess it's a safe for Tree though, although I am surprised that Tree uses that syntax already.

About:

this.getChildren().forEach(dijit._Container.prototype.removeChild);

Are you sure that "this" will be the correct value (a pointer to the widget) inside of _Container.removeChild()?

Of course removing the unused variable makes sense.

comment:3 Changed 10 years ago by bill

Milestone: tbd1.5
Type: enhancementtask

comment:4 Changed 10 years ago by Adam Peller

Milestone: 1.51.6

comment:5 Changed 9 years ago by bill

Resolution: wontfix
Status: newclosed

Can't depend on getChildren() returning a NodeList, as a matter of fact in 1.5 it doesn't. Maybe that will change for 2.0 in which case we'll update all usages of getChildren(), but for now I'm going to close this ticket.

Note: See TracTickets for help on using tickets.