Skip to content

Instantly share code, notes, and snippets.

@polaris
Created May 4, 2012 08:19
Show Gist options
  • Save polaris/2593239 to your computer and use it in GitHub Desktop.
Save polaris/2593239 to your computer and use it in GitHub Desktop.
SC Observer
UJAM.Node = SC.Object.extend({
parentNode: null,
childNodes: [],
childsDidChange: function () {
alert('child nodes changed');
}.observes('childNodes'),
addChild: function (node) {
this.childNodes.push(node);
this.notifyPropertyChange('childNodes');
}
});
UJAM.root = UJAM.Node.create({});
UJAM.NodeObserver = SC.Object.extend({
childsDidChange: function () {
alert('child nodes changed');
}.observes('UJAM.root.childNodes'),
});
UJAM.obs = UJAM.NodeObserver({});
UJAM.root.addChild(UJAM.Node.create({}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment