GitXplorerGitXplorer
a

reflux-stateful

public
10 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
c24c12a89dd984425d310d682d99c4f0272d487a

release v0.2.0

committed 10 years ago
Unverified
219c75e5eaf4de46457a08d1f9f3242912f45489

breaking changes: emit and getDefaultData

committed 10 years ago
Unverified
8b913df97e5ec7bcf72636437339d8ccb6f7a59a

release v0.1.0

committed 10 years ago
Unverified
b4324383475b1bcee8ae98d613b9e7a5735d99b0

readme

committed 10 years ago
Unverified
2ff4f1a9b918b257b559abaab18345b542702c72

emit method

committed 10 years ago
Unverified
d712011635946b0ac52e8530cd21516be15b8b30

initial commit

committed 10 years ago

README

The README file for this repository.

reflux-stateful

RefluxJS Mixin which provides state management methods for Stores.

Install

$ npm install reflux-stateful --save
$ bower install reflux-stateful --save

Usage

I've used ImmutableJS just for example.

If you're familiar with React's this.state and this.setState you already know how to use it with this mixin.

You need to use getDefaultData in your store to declare initial data.

var Stateful = require('reflux-stateful'),
	Immutable = require('immutable');

var Todos = Reflux.createStore({
	listenables: ... some actions ...
	mixins: [Stateful],

	getDefaultData: function(){
		return Immutable.OrderedMap();
	},

	add: function(title){
		var id = generateId(),
			newTodo = { title: title, completed: false };

		this.setState(this.state.set(id, newTodo));
	},

	remove: function(id){
		this.setState(this.state.remove(id));
	}
});

Mixin provides store.emit methods which allows you to fetch current state from store to React component

var TodoList = React.createClass({
	getInitialData: function(){
		return { items: store.emit() };
	}
});

Also, emit is render-like method for your data.

var Store = Reflux.createStore({
	mixins: [Stateful],

	getDefaultData: function(){
		return [];
	},

	emit: function(){
		return this.state.join(',');
	}
});

All stores listeners will receive result of emit method.

License

MIT License