Created
September 23, 2011 00:30
-
-
Save jiggliemon/1236451 to your computer and use it in GitHub Desktop.
Simple State Object
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
(function(global,_NAMESPACE_){ | |
var State = _NAMESPACE_.State = function(){ | |
return { | |
_states:{} | |
,_stateData: {} | |
,setState: function(name, data) { | |
if(this._states[name] && typeof data == 'undefined'){ | |
this.setState(this._states[name]); | |
return false; | |
} | |
if(typeof name == 'object'){ | |
for(var key in name){ | |
this.setState(key,name[key]); | |
} | |
return false; | |
} | |
this._stateData[name] = data; | |
if (typeof this['fireEvent'] === 'function') { | |
this.fireEvent([name,'set'].join('.'), data); | |
} | |
} | |
,getState: function(name, defaultVal) { | |
return this._stateData[name] === undefined ? defaultVal : this._stateData[name]; | |
} | |
}; | |
}; | |
})(global,_NAMESPACE_); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment