(Btw. don’t set ReactiveVar in onRendered because helper will throw error, that this var does not exist. All reactiveVars should be set in onCreated. The chain for rendering Template is:
thanks a lot for the quick response and pointing out the rendering chain!
I am actually just playing around with some newbie stuff
and found it strange that there is no direct access to a helpers data within an event.
This a stupid example for you that works.
The cool thing about it is that you can actually render multiple Instances of this template
and all would manage their own state.
<template name="exampleDatasourcesReactiveVar">
<h1>Reactive Variables</h1>
<input id="nameInput" type="text" value="{{name}}">
<button id="updateButton">Update</button>
{{processedName}}
</template>
// TOOLBOX
ReactiveTemplateTools = {
processName: function (name) {
return name + ' is not my lover!!';
}
}
// INIT REACTIVE-VAR
Template.exampleDatasourcesReactiveVar.onCreated(function() {
this.name = new ReactiveVar();
this.name.set('Billie Jeans');
this.processedName = new ReactiveVar();
this.processedName.set('');
});
// HELPERS
Template.exampleDatasourcesReactiveVar.helpers({
name: function () {
return Template.instance().name.get();
},
processedName: function() {
return Template.instance().processedName.get();
}
});
// EVENTS
Template.exampleDatasourcesReactiveVar.events({
'input #nameInput': function (event, template) {
template.name.set(event.target.value);
},
'click #updateButton': function (event, template) {
template.processedName.set(
ReactiveTemplateTools.processName(template.name.get())
);
},
});