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

Looking forward to add some more flexible usage into the doc #517

Closed KrisLeeCoder closed 7 years ago

KrisLeeCoder commented 7 years ago

I've read all the docs. It seems that the doc intend to make me combine Stores and Components with STATE. But I don't think it's flexible. In v2.x, I can use a receiver in React Components, and send data in Stores with method "trigger". In this way, I can deal with the data in the receiver, like formatting or filtering it, or trigger another action. the code may like this:

class MyComponent extends React.Component {
  constructor(props){}
  componentDidMount(){
    this.unsubscribe = MyStore.listen(this.onStoreChange.bind(this));
    MyAction.someAction();
  }
  onStoreChange(data) {
    // data is {loading: true}
    // do something with data, calling this.setState is up to the developer
  }
}

MyAction = Reflux.createAction("someAction");
MyAction.listen(() => {
    // do something
});

MyStore = Reflux.createStore({
  listenables: [MyAction, ],
  someAction: () => {
    this.trigger({loading: true});
  }
}

So confused, why not put this style in the doc and make it more flexible to use?

BryanGrezeszak commented 7 years ago

Seems like you're describing mapStoreToState literally to a tee.

It's completely up to the coder what gets passed to the component, how it's filtered, formatted, whether you call other stuff, etc. And if you just map an empty object or null then no setState is called at all.