Created
June 6, 2016 10:56
-
-
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
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
// 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; | |
} | |
} |
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
// 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