-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements changes to Grid to reflect problems in #23
- Loading branch information
1 parent
1137cc7
commit 3ca059f
Showing
7 changed files
with
100 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var without = require("lodash/array/without"); | ||
var flatten = require("lodash/array/flatten"); | ||
|
||
var Parent = { | ||
|
||
setupParent: function() { | ||
this.children = []; | ||
this.changedChildren = []; | ||
this.renderedChildren = []; | ||
}, | ||
|
||
addChild: function(child) { | ||
if(child.parent) child.parent.remove(child); | ||
this.children.push(child); | ||
child.parent = this; | ||
child.childId = this.children.length-1; | ||
child.changed(); | ||
}, | ||
|
||
removeChild: function(child) { | ||
this.children = without(this.children, child); | ||
this.changedChildren = without(this.changedChildren, child.childId); | ||
|
||
// Lower id's of all children above by one | ||
for(var i = child.childId; i < this.children.length; i++) { | ||
this.children[i].childId--; | ||
} | ||
|
||
// lower id's of all changedChildren by one | ||
for(var i = 0; i < this.changedChildren.length; i++) { | ||
if(this.changedChildren[i] > child.childId) this.changedChildren[i]--; | ||
} | ||
|
||
child.childId = null; | ||
child.parentNotified = false; | ||
child.parent = false; | ||
}, | ||
|
||
renderChildren: function(opts) { | ||
|
||
// loop through the changed children | ||
while(this.changedChildren.length > 0) { | ||
var childId = this.changedChildren.shift(); | ||
this.renderedChildren[childId] = this.children[childId].render(opts); | ||
this.children[childId].parentNotified = false; | ||
} | ||
|
||
// FIGURE OUT HOW NOT TO FLATTEN EVERY TIME! | ||
return flatten(this.renderedChildren, true); | ||
} | ||
|
||
|
||
}; | ||
|
||
module.exports = Parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters