Skip to content

Instantly share code, notes, and snippets.

@funkytek
Created November 2, 2016 18:51
Show Gist options
  • Save funkytek/95f91f467de8da4e867c3394de735ed6 to your computer and use it in GitHub Desktop.
Save funkytek/95f91f467de8da4e867c3394de735ed6 to your computer and use it in GitHub Desktop.
using append and remove hooks in mercury
const State = require('nhg/state')
const Value = require('nhg/value')
const h = require('nhg/h')
const AppendHook = require('append-hook')
const RemoveHook = require('remove-hook')
const createStore = require('weakmap-shim/create-store')
const Store = createStore()
module.exports = TestComponent
function TestComponent () {
const state = State({
active: Value(false),
hooks: {
load,
unload
}
})
return state
function load (element) {
// element is a reference to the container node
// you put the append hook on
// element.appendChild(...)
}
function unload () {
// ...
}
}
TestComponent.render = function render (state) {
h('test-component', {
append: AppendHook(state.hooks.load),
remove: RemoveHook(state.hooks.unload)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment