martyjs / marty

A Javascript library for state management in React applications
http://martyjs.org
MIT License
1.09k stars 77 forks source link

Manage multiple context #324

Closed LucaColonnello closed 9 years ago

LucaColonnello commented 9 years ago

Hi, how can i manage multiple context in a Marty.js App?

Suppose we want to create a UserList component with its UserListStore and we want to use this component in a form that let the users to select from the UserList a user for 3 different input.

The first input let users select only Admin users. The second input let users select only Developer users. The third input let users select only Reader users.

How can we do that in Marty.js? Flummox or Fluxxor provide incapsulation of Stores, Action Creators and Dispatcher into dedicated object. This let us to have multiple instances of some context.

jhollingworth commented 9 years ago

Hey, easiest way is to use Marty v0.10 which I'm planning on releasing tomorrow (You can use the beta right now). You have an application class which is equivalent to the Flummox/Fluxxor

class ExampleApp extends Application {
    constructor(options) {
        super(options);

        this.register({
            user: {
                store: require('./stores/userStore'),
                queries: require('./queries/userQueries'),
                actionCreators: require('./actions/userActionCreators'),
            }
        });
    }
}

var app = new ExampleApp();

app.user.store.getUser(1);
app.dispatcher.register(console.log.bind(console));
LucaColonnello commented 9 years ago

THIS IS AWESOME BOY!!! I'd love to work with React this way. :)

2015-05-26 22:04 GMT+02:00 James Hollingworth notifications@github.com:

Hey, easiest way is to use Marty v0.10 http://martyjs.org/v/0.10.0/blog/2015/05/27/marty-v0.10.html#singleton which I'm planning on releasing tomorrow (You can use the beta right now). You have an application class which is equivalent to the Flummox/Fluxxor

class ExampleApp extends Application { constructor(options) { super(options);

    this.register({
        user: {
            store: require('./stores/userStore'),
            queries: require('./queries/userQueries'),
            actionCreators: require('./actions/userActionCreators'),
        }
    });
}

} var app = new ExampleApp();

app.user.store.getUser(1); app.dispatcher.register(console.log.bind(console));

— Reply to this email directly or view it on GitHub https://github.com/martyjs/marty/issues/324#issuecomment-105650173.

Luca Colonnello 340 8707406 luca.colonnello91@gmail.com