Created
September 24, 2015 10:32
-
-
Save suchitpuri/343562bd486dc70d2f35 to your computer and use it in GitHub Desktop.
The store for managing the page loading
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
export default { | |
START: "startLoading", | |
DONE: "loadingComplete", | |
START_BUTTON: "startButtonLoading", | |
DONE_BUTTON: "doneButtonLoading" | |
} |
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
import ActionTypes from './action-types.js'; | |
import {handleAction} from '../../dispatcher'; | |
// import HelloSlave from '../slaves/HelloSlave.js'; | |
export default { | |
startPageLoading: function() { | |
handleAction({ | |
actionType: ActionTypes.START | |
}); | |
}, | |
startButtonLoading: function() { | |
handleAction({ | |
actionType: ActionTypes.START_BUTTON | |
}); | |
}, | |
doneButtonLoading: function() { | |
handleAction({ | |
actionType: ActionTypes.DONE_BUTTON | |
}); | |
}, | |
donePageLoading: function() { | |
handleAction({ | |
actionType: ActionTypes.DONE | |
}); | |
} | |
}; | |
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
// import AppDispatcher from '../app-dispatcher'; | |
import ActionTypes from './action-types.js'; | |
import {EventEmitter} from 'events'; | |
import {register} from '../../dispatcher'; | |
let _data = { | |
pageLoader: false, | |
butonLoader: false | |
}; | |
function _startPageLoader() { | |
_data.pageLoader = 30; | |
} | |
function _startButtonLoader(){ | |
_data.butonLoader = true; | |
} | |
function _completeButtonLoader(){ | |
_data.butonLoader = false; | |
} | |
function _completePageLoader(){ | |
_data.pageLoader = 100; | |
setTimeout(function(){ | |
_data.pageLoader = false; | |
_LoaderStore.emitChange(); | |
},400) | |
} | |
class LoaderStore extends EventEmitter { | |
getPageLoader() { | |
return _data.pageLoader; | |
} | |
getButtonLoader(){ | |
return _data.butonLoader; | |
} | |
emitChange() { | |
this.emit('change'); | |
} | |
addChangeListener(callback) { | |
this.on('change', callback); | |
} | |
removeChangeListener(callback) { | |
this.removeListener('change', callback); | |
} | |
} | |
let _LoaderStore = new LoaderStore(); | |
export default _LoaderStore; | |
register(({action, data}) => { | |
switch (action.actionType) { | |
case ActionTypes.START: | |
_startPageLoader(); | |
_LoaderStore.emitChange(); | |
break; | |
case ActionTypes.DONE: | |
_completePageLoader(); | |
_LoaderStore.emitChange(); | |
break; | |
case ActionTypes.START_BUTTON: | |
_startButtonLoader(); | |
_LoaderStore.emitChange(); | |
break; | |
case ActionTypes.DONE_BUTTON: | |
_completeButtonLoader(); | |
_LoaderStore.emitChange(); | |
break; | |
default: | |
break; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment