Skip to content

Instantly share code, notes, and snippets.

@NV
Created May 16, 2014 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NV/e2a857a3b82909a54d2d to your computer and use it in GitHub Desktop.
Save NV/e2a857a3b82909a54d2d to your computer and use it in GitHub Desktop.
Meteor temperature converter sample app. http://temperature.meteor.com
<head>
<title>Temperature converter</title>
</head>
<body>
{{> c2f}}
</body>
<template name="c2f">
<input type="number" value="{{celsius}}" id="c">℃ ⟷
<input type="number" value="{{fahrenheit}}" id="f">℉
</template>
// client/c2f.js
function c2f(c) {
return 9 / 5 * parseFloat(c) + 32;
}
function f2c(f) {
return 5 / 9 * (f - 32);
}
Session.setDefault('c', 0);
Template.c2f.celsius = function () {
return Session.get('c');
};
Template.c2f.fahrenheit = function () {
return c2f(Session.get('c'));
};
Template.c2f.events({
'input #c': function (e) {
Session.set('c', parseFloat(e.target.value));
},
'input #f': function(e) {
Session.set('c', f2c(parseFloat(e.target.value)));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment