I assume you can–my next question is can your helpers work in the Child component? That’s key for the combination of event handlers + helpers to be effective in like 50% of all scenarios. For example (and this time I won’t use ReactiveField since I’m not sure where the Data context is):
<template name="ParentComponent">
<button class="expand-collapse" />
{{#each posts}}
{{> ChildComponent}}
{{/each}}
</template>
<template name="ChildComponent">
{{#if expanded}}
<h1>{{title}}</h1>
<p>{{body}}</p>
{{else}}
<h1>{{title}}</h1>
{{/if}
</template>
class ParentComponent extends BlazeComponent {
onCreated: function() {
Template.instance().expandedIds == new ReactiveVar([ ]);
}
events() {
return super.events().concat({
'click button': this.triggerExpandCollapseAll,
'click h1': this.triggerExpandCollapseOne
});
}
//helper on parent
posts() {
return Posts.find();
}
//helper on child!! ..the point is it needs to share the state of the parent.
expanded() {
let ids = Template.instance().expandedIds.get(), // in my "Blaze Components" I have simply: `this.get('expandedIds')` since `Template.instance()` won't work.
return _.contains(ids, this._id);
}
triggerExpandCollapseAll() {
let ids = Template.instance().expandedIds.get(),
allIds = this.posts().map(post => post._id);
if(_.isEmpty(ids)) Template.instance().expandedIds.set(allIds);
else Template.instance().expandedIds.set([ ]);
}
triggerExpandCollapseOne() {
let ids = Template.instance().expandedIds.get();
if(!_.contains(ids, this._id) ids.push(this._id);
else ids = _.without(ids, this._id);
Template.instance().expandedIds.set(ids);
}
}
So this is how my Blaze Components works–helpers are inherited automatically (and dynamically) by child views at render time, while keeping the state from where they were defined. In that example, the state is needed on not just the parent, but also the child. And specifically within helpers. So that means the helpers must be automatically inherited by children. I checked your lookup.js file, and you don’t check the chain of parents for helpers that match–though, there could be other ways to accomplish this.