Skip to content

Instantly share code, notes, and snippets.

@axefrog
Last active April 1, 2016 01:59
Show Gist options
  • Select an option

  • Save axefrog/6ca075bd9cb8a71d28b5 to your computer and use it in GitHub Desktop.

Select an option

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.
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