The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Reflux - Creating Your First Action in React

Reflux - Creating Your First Action in React

2:44
Reflux uses Actions to tell the Stores when to update. We will wire Actions and Stores together to create a simple updatable age field React component.
Watch this lesson now
Avatar
egghead.io

Reflux uses Actions to tell the Stores when to update. We will wire Actions and Stores together to create a simple updatable age field React component.

Avatar
Denis Stoyanov

Very interesting this technology Reflux but more interesting if you will explain how can I use Reflux with rxjs or baconjs

In reply to egghead.io
Avatar
hipertracker

In general, stores can be used in many components. And the component can subscribe to many stores. It means, stores should know NOTHING about subscribed components states. So I would rather write something like:

var store = Reflux.createStore({
    listenables: [actions],
    onUpdateAge() {
        person.age = Math.random() * 100;
        this.trigger({person});
    }
});

var App = React.createClass({
    mixins: [Reflux.connect(store, 'updatePerson')],
    updatePerson(person) {
      this.setState({person})
    }
    //...
})
Avatar
Ryan

Hey John,

When I try to pass in data to onClick in the component I get an error saying: "Expected onClick listener to be a function, instead got type object" - same as if you pass onClick={actions.methodName()} with parens.

Why is this? And also how do we pass data to these calls? It's probably not a good pattern and that's why but I don't really understand why.

Thanks,
Ryan

Ok so this works:

onClick={() => { actions.updateMessage('this is the message'); }.bind(this) }

but thats just rediculous. if you have a second please let me know best practice on this...

Second Edit:

If anyone has this issue then the following works:

onClick={actions.ActionMethod.bind(this, param)}

no arrow / anon funcs just bind params to the component

In reply to egghead.io
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?