Skip to content

Instantly share code, notes, and snippets.

@tphdev
Last active March 19, 2017 16:11
Show Gist options
  • Save tphdev/b7f054229aca8b1936faa085052e6373 to your computer and use it in GitHub Desktop.
Save tphdev/b7f054229aca8b1936faa085052e6373 to your computer and use it in GitHub Desktop.
Data Store
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