Meteor 的 withTracker 函数的执行方式与之前的反应式容器函数 createContainer 有何不同? [英] How is Meteor's withTracker function executed differently than the former reactive container function createContainer?

查看:52
本文介绍了Meteor 的 withTracker 函数的执行方式与之前的反应式容器函数 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:

来自 meteor:react-packages 源代码:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆