Skip to content

Instantly share code, notes, and snippets.

@andrejewski
Created September 25, 2017 01:53
Show Gist options
  • Select an option

  • Save andrejewski/8804cb6f73be8a39fc52e183e0193ed6 to your computer and use it in GitHub Desktop.

Select an option

Save andrejewski/8804cb6f73be8a39fc52e183e0193ed6 to your computer and use it in GitHub Desktop.
Marko bindings for Raj
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