Skip to content

Instantly share code, notes, and snippets.

@Bondifrench
Created September 29, 2017 07:17
Show Gist options
  • Save Bondifrench/dfa46eed199660acdc5347b1ebf764a1 to your computer and use it in GitHub Desktop.
Save Bondifrench/dfa46eed199660acdc5347b1ebf764a1 to your computer and use it in GitHub Desktop.
Range filter proto
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)
@Bondifrench
Copy link
Author

Demo here

@Bondifrench
Copy link
Author

@JAForbes suggestions 1 and 2

@Bondifrench
Copy link
Author

@barneycarroll suggestion here

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