Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let initialState = {
- // Simplified for the purpose of this example ...
- applicants: { data: null, isFetching : false },
- applications: { data: null, isFetching : false },
- courses: { data: null, isFetching : false },
- assignments: { data: null, isFetching : false },
- };
- class AppState {
- // Use composition (instead of inheritance) with the Backbone model
- constructor(){
- this._data = new Backbone.NestedModel(initialState);
- }
- // Subscribe a listener, by subscribing it to the underlying Backbone model
- subscribe(listener){
- this._data.bind('change', listener);
- }
- // -------------------------- Public getters and setters -----------------------------------
- getApplicants(){
- return this._data.get('applicants.data');
- }
- isFetchingApplicants(){
- return this._data.get('applicants.isFetching');
- }
- setApplicants(applicants, isFetching=false){
- this._data.set('applicants.data', applicants);
- this._data.set('applicants.isFetching', isFetching);
- }
- setIsFetchingApplicants(isFetching){
- this._data.set('applicants.isFetching', isFetching);
- }
- // TODO: More getters and setters ...
- }
- let appState = new AppState();
- export {appState};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement