Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. let initialState = {
  2. // Simplified for the purpose of this example ...
  3. applicants: { data: null, isFetching : false },
  4. applications: { data: null, isFetching : false },
  5. courses: { data: null, isFetching : false },
  6. assignments: { data: null, isFetching : false },
  7. };
  8.  
  9.  
  10.  
  11. class AppState {
  12.  
  13. // Use composition (instead of inheritance) with the Backbone model
  14. constructor(){
  15. this._data = new Backbone.NestedModel(initialState);
  16. }
  17.  
  18. // Subscribe a listener, by subscribing it to the underlying Backbone model
  19. subscribe(listener){
  20. this._data.bind('change', listener);
  21. }
  22.  
  23.  
  24. // -------------------------- Public getters and setters -----------------------------------
  25.  
  26.  
  27. getApplicants(){
  28. return this._data.get('applicants.data');
  29. }
  30.  
  31. isFetchingApplicants(){
  32. return this._data.get('applicants.isFetching');
  33. }
  34.  
  35. setApplicants(applicants, isFetching=false){
  36. this._data.set('applicants.data', applicants);
  37. this._data.set('applicants.isFetching', isFetching);
  38. }
  39.  
  40. setIsFetchingApplicants(isFetching){
  41. this._data.set('applicants.isFetching', isFetching);
  42. }
  43.  
  44. // TODO: More getters and setters ...
  45. }
  46.  
  47.  
  48. let appState = new AppState();
  49. export {appState};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement