Created
September 29, 2017 07:17
-
-
Save Bondifrench/dfa46eed199660acdc5347b1ebf764a1 to your computer and use it in GitHub Desktop.
Range filter proto
This file contains hidden or 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
var stream = m.stream | |
var levels = { | |
5: 'Daycare or Kindergarten', | |
12: 'Primary', | |
16: 'Secondary', | |
18: 'Senior Secondary' | |
}; | |
var App = { | |
age: stream(0), | |
oninit: function (vnode) { | |
vnode.state.level= vnode.state.age.map(function (ag) { | |
if (ag > 18) return 'out of school'; | |
var index = Object.keys(levels).filter(function (lev) {return ag < Number(lev);}) | |
console.log(levels[index[0]]) | |
return ag && 'in ' + levels[index[0]]; | |
}) | |
}, | |
view: function (vnode) { | |
return [ | |
m('h3', 'School kids app'), | |
m('p', 'How old is your kid?'), | |
m('input', { | |
value: vnode.state.age(), | |
oninput: m.withAttr('value', vnode.state.age) | |
}), | |
m('h5', vnode.state.age()? 'Your kid is '+ vnode.state.age() +' and most likely ' + vnode.state.level() : '') | |
] | |
} | |
} | |
m.mount(document.body, App) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo here