Created
September 25, 2017 01:53
-
-
Save andrejewski/8804cb6f73be8a39fc52e183e0193ed6 to your computer and use it in GitHub Desktop.
Marko bindings for Raj
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
| const {program} = require('raj/runtime') | |
| module.exports = function markoProgram (createApp) { | |
| return class { | |
| onInput (input, out) { | |
| this.makeProgram(input, out) | |
| } | |
| onDestroy () { | |
| this.killProgram() | |
| } | |
| makeProgram (input, out) { | |
| const {view, ...app} = createApp(input) | |
| this.killProgram() | |
| this._killProgram = program({ | |
| ...app, | |
| view (state, dispatch) { | |
| view.render(state, out).then(result => { | |
| const component = result.getComponent() | |
| component.on('dispatch', (...args) => dispatch(...args)) | |
| }) | |
| } | |
| }) | |
| } | |
| killProgram () { | |
| if (this._killProgram) { | |
| this._killProgram() | |
| this._killProgram = undefined | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment