3den / fluxible

A pluggable container for isomorphic flux applications

Home Page:http://fluxible.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fluxible

npm version Build Status Coverage Status Dependency Status devDependency Status

Pluggable, singleton-free container for isomorphic Flux applications.

$ npm install --save fluxible

Gitter chat

Docs

Features

Extras

Usage

var Fluxible = require('fluxible');
var React = require('react');

// Action
var action = function (context, payload, done) {
    context.dispatch('FOO_ACTION', payload);
    done();
};

// Store
var createStore = require('fluxible/addons').createStore;
var Store = createStore({
    storeName: 'FooStore',
    handlers: {
        'FOO_ACTION': 'fooHandler'
    },
    initialize: function () { // Set the initial state
        this.foo = null;
    },
    fooHandler: function (payload) { 
        this.foo = payload;
    },
    getState: function () {
        return {
            foo: this.foo
        }
    }
});

// Component
var App = React.createClass({
    mixins: [Fluxible.FluxibleMixin], // Calls onChange when storeListeners emit change
    statics: {
        storeListeners: [Store]
    },
    getInitialState: function () {
        return this.getStore(Store).getState();
    },
    onChange: function () {
        this.setState(this.getStore(Store).getState());
    },
    render: function () {
        return <span>{this.state.foo}</span>
    }
});

// App
var fluxibleApp = new Fluxible({
    component: App
});
fluxibleApp.registerStore(Store);

// Bootstrap
var context = fluxibleApp.createContext();
context.executeAction(action, 'bar', function () {
    console.log(React.renderToString(context.createElement()));
});

License

This software is free to use under the Yahoo Inc. BSD license. See the LICENSE file for license text and copyright information.

About

A pluggable container for isomorphic flux applications

http://fluxible.io

License:Other


Languages

Language:JavaScript 100.0%