为什么帮助程序在未引用 #with 块中的任何反应变量时会重新运行



为什么foo更改时,#with -block 内的帮助程序insideWith会被重新计算?帮助程序未引用任何反应式数据源!

傅.js

var foo;
if (Meteor.isClient) {
  foo = new ReactiveVar();
  foo.set(0);
  Template.board.helpers({
    obj: function() {
      return {
        foo: foo.get()
      };
    },
    insideWith: function() {
      return console.log('insideWith');
    },
    fooInsideWith: function() {
      foo.get();
      return console.log("fooInsideWith ");
    },
    notInsideWith: function() {
      return console.log('notInsideWith');
    },
    fooNotInsideWith: function() {
      foo.get();
      return console.log("fooNotInsideWith ");
    }
  });
  Template.board.events({
    'click button': function(e, t) {
      return foo.set(Math.floor(Math.random() * 10));
    }
  });
}

傅.html

<body>
    {{> bar}}
</body>
<template name="bar">
    <div class="bar">
        <button>Random</button>
        <div>
            {{#with obj}}
                {{insideWith}}
                {{fooInsideWith}}
            {{/with}}
        </div>
        <div>
            <span>{{obj.foo}}</span>
            {{notInsideWith}}
            {{fooNotInsideWith}}
        </div>
    </div>
</template>

来自注释 (@fuzzybabybunny):

每当 OBJ 更改时,{{#with}} 将自动运行,因为 Obj 是反应式数据源 foo 的帮助程序。{{insideWith}} 嵌套在 {{#with}} 中,所以显然它也在运行。

最新更新