Created
December 5, 2019 17:01
-
-
Save ftaiolivista/6bb6dbb64089b1c9651507f8ba7c9fb6 to your computer and use it in GitHub Desktop.
Components
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
const Mutor = function (f = i => i, argz = {}) { | |
const _func = Array.isArray(f) ? f.reduce((f, c) => (f ? c(f) : c)) : f | |
const _arg = Array.isArray(argz) ? Object.assign({}, ...argz) : argz | |
const m = Object.assign( | |
function (a) { | |
return _func(Object.assign({}, _arg, a)) | |
}, | |
Array.isArray(f) ? f[0] : f | |
) | |
m._func = _func | |
m._arg = _arg | |
m.pipe = f => | |
pipe( | |
f, | |
m | |
) | |
m.mutate = argz => mutate(f, m) | |
return m | |
} | |
const pipe = function (f, m) { | |
return Mutor.of([m._func, f], m._arg) | |
} | |
const mutate = function (argz, m) { | |
return Mutor.of(m._func, [m._arg, argz]) | |
} | |
Mutor.of = Mutor | |
export { Mutor } | |
// ========================================================== | |
// EXANPLE USAGE | |
function Subcomponent (sources) {} | |
function Component (sources) { | |
const actions = intent(sources) | |
const state$ = model(actions, Mutor.of(Subcomponent, sources)) | |
const vdom$ = view(state$) | |
return { | |
DOM: vdom$ | |
} | |
} | |
function model (actions, subcomponent) { | |
..... | |
const isolated = subcomponent.pipe(isolate) | |
const snks = isolated({ | |
someAdditionalStream$: xs.of([]) | |
}) | |
..... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment