Question: Reflux: How to listen to a subset of actions using `listanables` or `this.listenToMany`?

Question

Reflux: How to listen to a subset of actions using `listanables` or `this.listenToMany`?

Answers 1
Added at 2016-10-26 13:10
Tags
Question

Imagine that you have a huge actions object and some components / stores just want to listen subset of it.

var actions = Reflux.createActions({ /* lots of actions with children*/});

How to listen only for a subset of these action and not do manually one by one this.listenTo()? Easiest way?

Answers
nr: #1 dodano: 2016-10-26 13:10

So you do it easy.

In store:

// ...
var actions = Reflux.createActions({ /* lots of actions with children*/});
module.exports = Reflux.createStore({
     listenables: {subsetKey: actions.subsetKey},
     // ...

In component:

// ...
var actions = Reflux.createActions({ /* lots of actions with children*/});
module.exports = React.createClass({
      mixins: [Reflux.ListenerMixin],
      componentDidMount() {
           this.listenToMany({subsetKey: actions.subsetKey});
      }
      // ...
Source Show
◀ Wstecz