Last active
July 29, 2017 18:10
-
-
Save ahoereth/a75d2d6528b1844ad503 to your computer and use it in GitHub Desktop.
Minimal meteor reactive variable example. http://meteorpad.com/pad/kajGdYLfTrEkE5NtL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template name="meteor_reactive_var"> | |
<div>{{count}}</div> | |
<button>Increment Count</button> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the quick example.