GitXplorerGitXplorer
a

reflux-stateful

public
10 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
70bc2a76222fdfca3582e68ace21aa22bae745e1

release v0.3.1

committed 10 years ago
Unverified
399e0fb640c1b8b9acebf8e6e9075741a463c346

remove spreading

committed 10 years ago
Unverified
4aa901ea12b34d6ae771b55c3ab3aafaa378b4cd

release v0.3.0

committed 10 years ago
Unverified
6f8a3fdd0061e50030ae9bdd8e6d004a7596cccc

assign newState

committed 10 years ago
Unverified
efffe9ff78dc4cd7ade2b00ecf107d54523a2662

release v0.2.1

committed 10 years ago
Unverified
11011bf50c0e4a4c1bce4943e4dd90f1cc73298f

bower manifest

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