-
-
Save geoffreyd/4cdb482c27eb896e632d to your computer and use it in GitHub Desktop.
StateChart Observer Code
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
SC.mixin(Ki.State.prototype, | |
/** SC.Object.prototype */ { | |
/** | |
Adds an observer that dispatches a "propertyChanged" (or `action` if set) | |
event to the object's statechart. | |
@param {String} key the property to observe | |
@param {SC.Object} target the object you want to observe the key on | |
@param {String} action Optional action function to call. | |
@returns {Function} the actual observer (need to remove later) | |
*/ | |
addStatechartObserver: function(target, key, action) { | |
var state = this.statechart; | |
if (!action) {action = 'propertyChanged'} | |
var fun = function(target, key, value, revision) { | |
state.sendEvent(action, target, key, revision); | |
}; | |
target.addObserver(key, target, fun); | |
return fun ; | |
}, | |
/** | |
Adds an observer that dispatches a "propertyChanged" event to the object's | |
statechart. | |
@param {String} key the property to observe | |
@param {SC.Object} target the object you were observing the key on | |
@param {Function} the function object returned from addStatechartObserver | |
@returns {SC.Object} receiver | |
*/ | |
removeStatechartObserver: function(target, key, fun) { | |
target.removeObserver(key, target, fun) ; | |
return this ; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment