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

multiple store listen one action #456

Closed beiluo closed 8 years ago

beiluo commented 8 years ago
//actions.js
var _ = {sync: true, children: ['completed', 'failed']};
module.exports = Reflux.createActions({
    getNews: _,
    addNews:_
});
//createStore.js
var actions =  require("./actions");
module.exports = Reflux.createStore({
    listenables: actions,
    init: function () {

    },
    OnGetNews: function () {
        console.log('OnGetNews')
        this.trigger({});
    }
});
//listStore.js
var actions =  require("./actions");
Reflux.createStore({
    listenables: actions,
    init: function () {

    },
    OnGetNews: function () {
        console.log('OnGetNews')
        this.trigger({});
    },
    OnAddNews: function () {
        console.log('OnAddNews')
        this.trigger({});
    }
});
//components create.jsx
import actions from './actions'
import store from './createStore'
module.exports = React.createClass({
  mixins: [
    ListenerMixin,
    Reflux.connect(store),
  ],
  componentDidMount() {
    actions.getNews();
  },
  render(){
    //body
  }
})
//components list.jsx
import actions from './actions'
import store from './listStore'
module.exports = React.createClass({
  mixins: [
    ListenerMixin,
    Reflux.connect(store),
  ],
  componentDidMount() {
    //actions.getNews();
  },
  render(){
    //body
  }
})

The first loading list.jsx Then load create.jsx Result:

OnGetNews
OnGetNews

I want results:

OnGetNews

How to cancel listStore listen?

devinivy commented 8 years ago

You should be able to listStore.stopListeningTo(actions.getNews) when you want the store to stop listening to that action.

beiluo commented 8 years ago

thank you