Skip to content
lubelski edited this page Nov 16, 2014 · 1 revision

Stores are the heart and sole of a flux app.

App.createStore(name, storeOptions)

Example:
Kitchen = pipeline.createApp()

Kitchen.createStore('tortillas', 
  API: 
    getTortillaCount: (brand) -> @get(brand)
    getTotalTortillaCount: -> _.reduce(@getData(), (sum, count) -> sum = sum + count)

  actions: 
    addToritilla: (brand, count) -> 
      current = @get(brand) 
      @update(brand, current + count)

Kitchen.createStore('pantry', 
  actions: 
    addToritilla: -> 
      {brand, count} = @action

@action is always available in the context where a stores callback is evaluated. This, combined with the actions packager function, forces the variable and property names to be the same across multiple stores' callbacks. This makes it easier to move between different parts of the codebase.

Clone this wiki locally