【发布时间】:2017-11-27 23:02:10
【问题描述】:
我正在开发一个具有通量模式的项目,该模式使用通量容器函数“createFunctional”,如下所示:
import {Container} from 'flux/utils';
import View from './MyView.js';
import AppStore from './AppStore.js';
function getStores() {
return [
AppStore
];
}
function getState() {
var state = {
pie: AppStore.getState(),
};
return state;
}
export default Container.createFunctional(View, getStores, getState);
我想更好地理解这段代码,但我发现很难找到关于这个函数的文档。
我猜这是以某种方式将 store 和 state 函数绑定到视图,并且它在某种程度上与此代码相同(我已根据 example on the flux website 进行了重组):
class MyView extends Component {
static getStores() {
return [AppStore];
}
static calculateState(prevState) {
return {
pie: AppStore.getState(),
};
}
render() {
return <div>blah..</div>;
}
}
const container = Container.create(CounterContainer);
【问题讨论】:
-
我之前没有使用过纯助焊剂,但查看源代码这似乎类似于 redux 中的
connect。我认为它监视商店的变化,当发生变化时,它会将整个状态作为道具传递给底层组件(第一个参数)。
标签: reactjs flux reactjs-flux