Meteor 的 withTracker 函数的执行方式与之前的反应式容器函数 createContainer 有何不同? [英] How is Meteor's withTracker function executed differently than the former reactive container function createContainer?
问题描述
以下是 withTracker()
函数调用的示例,其中包括在 Javascript 中使用顺序括号.
The following is an example of withTracker()
function call which includes usage of sequential parentheses in 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()
函数,它被调用如下,目的与上述相同.
The former reactive container for React components in Meteor was the createContainer()
function and it was called like the following for the same purpose of the above one.
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);
这两个函数的执行有什么区别?
What is the difference in the execution of these two functions?
推荐答案
它们的执行没有区别,因为 withTracker
只是 createContainer
调用的包装器:
There is no difference at their execution, because withTracker
is just a wrapper for createContainer
call:
From meteor:react-packages
source code:
const withTracker = fn => C => createContainer(fn, C);
或者,如果您愿意:
function withTracker(fn) {
return function(C) {
return createContainer(fn, C);
}
}
这篇关于Meteor 的 withTracker 函数的执行方式与之前的反应式容器函数 createContainer 有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!