Skip to content

Instantly share code, notes, and snippets.

@mgood
Created March 20, 2010 01:48
Show Gist options
  • Save mgood/338395 to your computer and use it in GitHub Desktop.
Save mgood/338395 to your computer and use it in GitHub Desktop.
module("Observing global vs. local properties ", {
setup: function() {
objectA = SC.Object.create({
calledLocalObserver: false,
calledGlobalObserver: false,
calledMixedObserver: false,
locallyObservedProperty: 'beingWatched',
testLocalObserver: function() {
this.calledLocalObserver = true;
}.observes('locallyObservedProperty'),
testGlobalObserver: function() {
this.calledGlobalObserver = true;
}.observes('Namespace.objectB.globallyObservedProperty'),
testMixedObserver: function() {
this.calledMixedObserver = true;
}.observes('locallyObservedProperty',
'Namespace.objectB.globallyObservedProperty')
});
objectB = SC.Object.create({
globallyObservedProperty: 'beingWatched'
});
Namespace = {
objectA: objectA,
objectB: objectB
};
}
});
test("test setting a property observed on the current object", function() {
objectA.set('locallyObservedProperty', 'notifyObserver');
equals(objectA.calledLocalObserver, true, 'should notify local observer');
equals(objectA.calledGlobalObserver, false, 'should not notify global observer');
equals(objectA.calledMixedObserver, true, 'should notify mixed observer');
});
test("test setting a propety observed with a fully-qualified path", function() {
objectB.set('globallyObservedProperty', 'notifyObserver');
equals(objectA.calledLocalObserver, false, 'should not notify local observer');
equals(objectA.calledGlobalObserver, true, 'should notify global observer');
equals(objectA.calledMixedObserver, true, 'should notify mixed observer');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment