Created
April 28, 2019 15:32
-
-
Save FbN/02618ca663b0b205cda5b769bcb40670 to your computer and use it in GitHub Desktop.
Item VM
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
// m: Mithril lib | |
// M: Most Core lib | |
import { m, M } from '../vendor.mjs' | |
// T: Triggers imported from High-Leve model Todo | |
// $list: Stream imported from High-Leve model Todo | |
import { T as TodoT, $list, enter, esc } from '../model/todo.mjs' | |
// Utility function to generate many streams/triggers | |
import { adapters } from '../mm.mjs' | |
// The VM function used by Item component | |
export default function itemVM (vnodeR) { | |
// Local Stream/Triggers generation | |
const { streams: S, triggers: T } = adapters([ | |
'keyup', | |
'input', | |
'complete', | |
'editing', | |
'delete', | |
'confirmEditing' | |
]) | |
// // Other stre... | |
// Streams can depends on high-level streams | |
// extending the global stream network. | |
const $item = M.startWith( | |
vnodeR.attrs.item, | |
M.map( | |
list => list.find(item => item.id === vnodeR.attrs.key) || {}, | |
$list | |
) | |
) | |
// Streams can generate events on high-level model streams | |
// Most tap function is used for side-effects | |
const $completeEffect = M.tap( | |
TodoT._$update, | |
M.map( | |
item => Object.assign({}, item, { completed: !item.completed }), | |
M.sample($item, S.$complete) | |
) | |
) | |
// ... | |
// We return an array of triggers an streams. | |
// Streams named like status will sink to change status values | |
return [ | |
T, | |
{ | |
$item: $itemRes, | |
$editing: $editingStatus, | |
$editingText, | |
$deleteItem | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment