How does the Meteor withTracker function execute differently than the first createContainer reactive container function?

The following is an example of a function call withTracker()that includes the use of consecutive 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);

The first reactive container for React components in Meteor was a feature createContainer(), and it was named as follows for the same purpose as the previous 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 performing these two functions?

+2
source share
2 answers

There is no difference in their execution, because it withTrackeris just a wrapper for calling createContainer:

From meteor:react-packagessource code :

const withTracker = fn => C => createContainer(fn, C);

Or if you prefer:

function withTracker(fn) {
  return function(C) {
    return createContainer(fn, C);
  }
}
+2
source

, , +.

const someContainer = withTracker((props) => ({
  someFunction(parms) { ..function code },
  someVariable: value,
}))(ComponentName);

const someContainer = withTracker((props) => {
  const someFunction = (parms) => { ..function code };
  const someVariable = value;
  return {
    someFunction,
    someVariable,
  }
})(ComponentName);

, ( "" ) , "" , .

0

Source: https://habr.com/ru/post/1690219/


All Articles