reflux / refluxjs

A simple library for uni-directional dataflow application architecture with React extensions inspired by Flux
BSD 3-Clause "New" or "Revised" License
5.36k stars 330 forks source link

can react.createClass mixins two Reflux.connect stores? #463

Closed aoyunfeng closed 7 years ago

aoyunfeng commented 8 years ago

code like

var Test=React.createClass({ mixins: [Reflux.connect(oneStore,"one"),Reflux.connect(twoStore,"two")],

tjankowski commented 8 years ago

Hi @aoyunfeng,

Yes, you can use it like:

export default React.createClass({

    contextTypes: {
        lang: React.PropTypes.string
    },

    mixins: [
        Reflux.connect(AppStore, 'appContext'),
        Reflux.connect(SyncStore, 'syncStatus'),
        Reflux.listenTo(AuthenticationStore, 'onAuthentication')
    ],
BryanGrezeszak commented 7 years ago

In addition to tjankowski's answer, you'd also do this in the ES6 API via:

class MyClass extends Reflux.Component
{
    constructor(props)
    {
        super(props);
        this.stores = [OneStore, AnotherStore];
    }

    render()
    {
        // ...
    }
}

The states of both Reflux.Store objects would get merged into the state of MyClass.