Last active
March 19, 2017 16:11
-
-
Save tphdev/b7f054229aca8b1936faa085052e6373 to your computer and use it in GitHub Desktop.
Data Store
This file contains hidden or 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
export const STORE = { | |
_data: { | |
shoutOutList: [], | |
shownRatingType: 'PG', | |
currentNavRoute: '' | |
}, | |
getStoreData: function(){ | |
return this._data | |
}, | |
setStore: function(storeProp, payload){ | |
if (typeof this._data[storeProp] === 'undefined' ) { | |
throw new Error('Cannot set property that does not exist on STORE._data') | |
} | |
this._data[storeProp] = payload | |
if(typeof this._callMeLaterPls === 'function'){ | |
this._callMeLaterPls() | |
} | |
}, | |
onStoreChange: function(cbFunc){ | |
if(typeof cbFunc !== 'function'){ | |
throw new Error('argument to store must be a FUNCTION') | |
} | |
if(typeof this._callMeLaterPls === 'function'){ | |
throw new Error('Store is already listening') | |
} | |
this._callMeLaterPls = cbFunc | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment