How to identify component in FLUX of React

不想你离开。 提交于 2020-01-17 05:06:19

问题


I am pretty new to FLUX, so I started with the TODO example on their website: https://facebook.github.io/flux/docs/todo-list.html

In the Listening to Changes with a Controller-View part:

There is on event binding in TodoApp:

componentDidMount: function() {
    TodoStore.addChangeListener(this._onChange);
}

and this._onChange is like:

 _onChange: function() {
    this.setState(getTodoState());
}

The addChangeListener from TodoStore is like:

addChangeListener: function(callback) {
    this.on(CHANGE_EVENT, callback);
}

What confused me here is:

It seems that the store just simply register that _onChange(), but how does the TodoStore know whose _onChange() need to be called if there are multiple TodoApps rendered on the page.


回答1:


TodoStore simply emits the event and every component that is listening to that store will update. So if you have two TodoApps on page, both will update.



来源:https://stackoverflow.com/questions/33926833/how-to-identify-component-in-flux-of-react

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!