Created
April 28, 2019 15:47
-
-
Save FbN/32b013a9338177503220fd90c15781b4 to your computer and use it in GitHub Desktop.
Item View
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
// m: Mithril lib | |
import { m } from '../vendor.mjs' | |
export default function itemView ( | |
/* Immutable component state */ | |
{ item, editing, editingText }, | |
/* Trigger functions returned by Item VM */ | |
{ | |
_$keyup, | |
_$input, | |
_$complete, | |
_$editing, | |
_$delete, | |
_$confirmEditing | |
}, | |
/* Immutable declarative vnode */ | |
vnodeR | |
) { | |
return m( | |
'li', | |
{ | |
key: item.id, | |
class: | |
(item.completed ? 'completed' : '') + | |
(editing ? ' editing' : '') | |
}, | |
[ | |
m('.view', [ | |
m('input.toggle[type=checkbox]', { | |
onclick: _$complete, | |
checked: item.completed | |
}), | |
m('label', { ondblclick: _$editing }, item.title), | |
m('button.destroy', { onclick: _$delete }) | |
]), | |
m('input.edit', { | |
onkeydown: _$keyup, | |
oninput: _$input, | |
onupdate: vnode => editing && vnode.dom.focus(), | |
onblur: e => editing && _$confirmEditing(e), | |
value: editingText | |
}) | |
] | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment