Opened 10 years ago

Closed 10 years ago

#9986 closed defect (fixed)

dijit._Container.getIndexOfChild() code reduction

Reported by: Les Owned by: bill
Priority: high Milestone: 1.4
Component: Dijit Version: 1.3.2
Keywords: Cc:
Blocked By: Blocking:

Description

This is lightly tested.

These two methods should be functionally equivalent, but the last one is simpler and shorter.

getIndexOfChild: function(/*Widget*/ child){
	// summary:
	//		Gets the index of the child in this container or -1 if not found
	var children = this.getChildren();
	for(var i=0, c; c=children[i]; i++){
		if(c == child){ 
			return i; // int
		}
	}
	return -1; // int
}
getIndexOfChild: function(/*Widget*/ child){
	// summary:
	//		Gets the index of the child in this container or -1 if not found
	return dojo.indexOf(this.getChildren(), child);
}

Change History (3)

comment:1 Changed 10 years ago by bill

Component: GeneralDijit
Owner: anonymous deleted

That does seem shorter, although it strikes me as strange that both the old and new code is comparing _Widget objects rather than just comparing the widget id's.

comment:2 Changed 10 years ago by bill

Milestone: tbd1.4
Owner: set to bill
Status: newassigned

Anyway, I will make your suggested change, thanks!

comment:3 Changed 10 years ago by bill

Resolution: fixed
Status: assignedclosed

(In [20280]) dijit._Contained and dijit._Container code reduction from Les (CLA on file) and me.

Seems like there is still a lot of redundancy though between _Container (_getSiblingOfChild, _nextElement) and _Contained (_getSibling, _getPrevSibling, _getNextSibling). The only difference I see is that _Container._getSiblingOfChild() skips over non-Widget siblings; not sure if/why that code is needed. Also might make sense to just use dojo.query() for these methods.

Also updating API doc for return codes.

Fixes #9985, #9986 !strict.

Note: See TracTickets for help on using tickets.