Skip to content

souptown/refluxjs-aggregate-store-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

refluxjs-aggregate-store-pattern

This is a pattern for creating aggregate stores in refluxjs.

  • Parent store state has a property that references the child store state
    • This is a reference, not a copy
  • Parent store listens for child store trigger events
  • Child passes entire state when triggering
var ParentStore = Reflux.createStore({

  init: function () {
    // Initial state
    this.state = {
      child: ChildStore.state
    };
    
    this.listenTo(ChildStore, this.onChildStoreEvent);
  },

  // Child stores changes
  onChildStoreEvent: function (newState) {
    this.state.child = newstate;
    this.trigger(this.state);
  }
  
});

var ChildStore = Reflux.createStore({
  listenables: ChildActions, // ChildActions.changeFoo is an action
  
  init: function () {
    this.state = {
      foo: ''
    };
  }
  
  onChangeFoo: function (newFoo) {
    this.state.foo = newFoo;
    this.trigger(this.state);
  }
  
});

Example

Shopping cart example

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published