Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bloodyowl/store
a simple store that works well with Flux
https://github.com/bloodyowl/store
Last synced: 19 days ago
JSON representation
a simple store that works well with Flux
- Host: GitHub
- URL: https://github.com/bloodyowl/store
- Owner: bloodyowl
- License: mit
- Created: 2014-11-18T10:08:12.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-28T17:21:14.000Z (almost 10 years ago)
- Last Synced: 2024-11-20T18:02:25.756Z (23 days ago)
- Language: JavaScript
- Homepage:
- Size: 180 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# store
> a simple store that works well with Flux
[![Build Status](https://travis-ci.org/bloodyowl/store.svg)](https://travis-ci.org/bloodyowl/store)
## install
```sh
$ npm install bloody-store
```## require
```javascript
var Store = require("bloody-store")
```## api
### var store = new Store(spec)
base class for Stores, implementing the EventEmitter logic, Store instances must own a `getStore` method
### store.addChangeListener(func)
adds a change listener to the store
### store.removeChangeListener(func)
removes a change listener to the store
### store.emitChange()
runs all the listeners that are currently in place in the order they've been added
### store.createReactMixin([spec])
returns a mixin that can be used by a React component, optionally merged with the spec
## example
```javascript
var AppDispatcher = require("../AppDispatcher")
var ActionTypes = require("../constants").ActionTypes
var Store = require("Store")// where you hold your data
var _store = {}var MyStore = new Store({
// mandatory
getStore() {
return _store
},dispatchToken : AppDispatcher.regiter(function(payload){
var action = payload.action
switch(action.type) {
case ActionTypes.ADD_FOO:
_store = Object.assign({}, _store, {foo : "bar"})
MyStore.emitChange()
break
default:
// do nothing
break
}
})
})
```and in your view
```javascript
var MyStore = require("../stores/MyStore")React.createClass({
mixins : [
MyStore.createReactMixin()
],
render() {
return (
{this.state.foo}
)
}
})
```## [license](LICENSE.md)