Skip to content

Instantly share code, notes, and snippets.

@staltz
Created June 6, 2016 10:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save staltz/bb49973bb9598abfd33cf3acde768403 to your computer and use it in GitHub Desktop.
Save staltz/bb49973bb9598abfd33cf3acde768403 to your computer and use it in GitHub Desktop.
How to use Stanga (https://github.com/milankinen/stanga) as a wrapper, not as a driver
// Generic helper function that takes a main() (the top-level component)
// and wraps it with Stanga logic
function wrapWithStanga(main, initialState) {
return function (sources) {
const modProxy$ = new Subject();
const modelSource = Model(initialState)(modProxy$);
sources.model = modelSource;
const sinks = main(sources);
sinks.model.subscribe(modProxy$);
return sinks;
}
}
// Usage example
function main(sources) {
// return sinks...
}
const initialState = {name: 'Sara', job: 'Designer'}
Cycle.run(wrapWithStanga(main, initialState), {
DOM: makeDOMDriver('#app')
});
// See a full example at http://www.webpackbin.com/EkzrrSRmZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment