下面是一个例子withTracker()
函数调用,其中包括在 Javascript 中使用连续括号。
export default withTracker(props => {
const handle = Meteor.subscribe('todoList', props.id);
return {
currentUser: Meteor.user(),
listLoading: !handle.ready(),
tasks: Tasks.find({ listId: props.id }).fetch(),
};
})(Foo);
Meteor 中 React 组件的前反应容器是createContainer()
函数,出于与上述函数相同的目的,如下调用它。
export default FooContainer = createContainer(props => {
const handle = Meteor.subscribe('todoList', props.id);
return {
currentUser: Meteor.user(),
listLoading: ! handle.ready(),
tasks: Tasks.find({ listId: props.id }).fetch(),
};
}, Foo);
这两个函数的执行有什么区别呢?
它们的执行没有区别,因为withTracker
只是一个包装createContainer
call:
From meteor:react-packages源代码 https://github.com/meteor/react-packages/blob/master/packages/react-meteor-data/withTracker.jsx#L3:
const withTracker = fn => C => createContainer(fn, C);
或者,如果您愿意:
function withTracker(fn) {
return function(C) {
return createContainer(fn, C);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)