Skip to content

Instantly share code, notes, and snippets.

@ahoereth
Last active July 29, 2017 18:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahoereth/a75d2d6528b1844ad503 to your computer and use it in GitHub Desktop.
Save ahoereth/a75d2d6528b1844ad503 to your computer and use it in GitHub Desktop.
Minimal meteor reactive variable example. http://meteorpad.com/pad/kajGdYLfTrEkE5NtL
<template name="meteor_reactive_var">
<div>{{count}}</div>
<button>Increment Count</button>
</template>
// Initialize reactive variable.
Template.meteor_reactive_var.created = function() {
this.count = new ReactiveVar(0);
};
// Expose reactive variable to template.
Template.meteor_reactive_var.helpers({
count: function() {
return Template.instance().count.get();
}
});
// Listen to event to update reactive variable
Template.meteor_reactive_var.events({
'click button': function(e, tmpl) {
var currentCount = tmpl.count.get();
tmpl.count.set(1+currentCount);
}
});
@macroramesh6
Copy link

Thanks for the quick example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment