Created
November 2, 2016 18:51
-
-
Save funkytek/95f91f467de8da4e867c3394de735ed6 to your computer and use it in GitHub Desktop.
using append and remove hooks in mercury
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 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