Last active
April 1, 2016 01:59
-
-
Save axefrog/6ca075bd9cb8a71d28b5 to your computer and use it in GitHub Desktop.
Experiment: Context driver providing a way to recognise the inherit coupling of state with a view, its metadata and children. A context object is built and extended by each nested component as it is emitted to its parent.
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
| export function makeContextDriver(domDriver) { | |
| return function(context$) { | |
| const ctx$ = context$.multicast(); | |
| const vtree$ = ctx$.filter(c => c.vtree).map(c => c.vtree); | |
| const state$ = ctx$.filter(c => c.state).map(c => c.state); | |
| const metadata$ = ctx$.filter(c => c.metadata).map(c => c.metadata); | |
| return { | |
| DOM: domDriver(vtree$), | |
| state$, | |
| metadata$ | |
| }; | |
| }; | |
| } | |
| export function makeClientContextDriver(domDriver) { | |
| function setTitle(title) { | |
| document.title = title; | |
| } | |
| return function(context$) { | |
| const contextDriver = makeContextDriver(domDriver); | |
| const source = contextDriver(context$); | |
| source.metadata$ | |
| .filter(m => m.title) | |
| .map(m => m.title) | |
| .observe(setTitle); | |
| return source; | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment