Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "cargo-bay", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A base store for flux applications", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -7,10 +7,70 @@ # cargo-bay | ||
#### Run examples | ||
## Install | ||
`npm install cargo-bay` | ||
## Usage | ||
This is the base store for the storages in your flux application. It will provide the base events you will merge into your store, so you can have a standard interface to listening to those storage updates. This will let you know that the state in your store has changed, and you can call render (or whatever you want) in your view. | ||
``` | ||
npm install | ||
#/stores/HelloWorldStore.js | ||
npm run examples | ||
'use strict'; | ||
var LCARS = require('lcars'); | ||
var CargoBay = require('cargo-bay'); | ||
var HelloWorldConstants = require('./../constants/HelloWorldConstants'); | ||
var merge = require('amp-merge'); | ||
var HelloWorldData = { | ||
_data: { | ||
name: "Bob", | ||
age: undefined | ||
}, | ||
clonedData: function() { | ||
return JSON.parse(JSON.stringify(this._data)); | ||
} | ||
}; | ||
var _setAge = function(age){ | ||
var data = HelloWorldData.clonedData(); | ||
data.age = age; | ||
HelloWorldData._data = data; | ||
return HelloWorldData.clonedData(); | ||
}; | ||
var HelloWorldStore = merge(CargoBay, { | ||
getDataFromStore: function(){ | ||
return HelloWorldData.clonedData(); | ||
} | ||
}); | ||
HelloWorldStore.dispatchToken = LCARS.register(function(action){ | ||
switch (action.type){ | ||
case HelloWorldConstants.DemoActions.SET_AGE: | ||
_setAge(action.data.age); | ||
HelloWorldStore.emitChange(); | ||
break; | ||
} | ||
}); | ||
module.exports = HelloWorldStore; | ||
``` | ||
In your component | ||
``` | ||
var HelloWorldStore = require('./../stores/HelloWorldStore') | ||
componentDidMount: function() { | ||
HelloWorldStore.addChangeListener(function(){ | ||
var state = this.getStateFromStores(); | ||
this.setState(state); | ||
}.bind(this)); | ||
}, | ||
``` | ||
You can see an example of this in [freighter](https://github.com/sstate/freighter/tree/master/examples). | ||
#### Run tests | ||
@@ -17,0 +77,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6184
81