Skip to content

Instantly share code, notes, and snippets.

@zaceno
Created October 18, 2019 13:53
Show Gist options
  • Save zaceno/6cbdc0128cc093b2a3026afd56e8f05f to your computer and use it in GitHub Desktop.
Save zaceno/6cbdc0128cc093b2a3026afd56e8f05f to your computer and use it in GitHub Desktop.
withHead hyperapp HOA
const withHead = (() => {
let _setHead = null
let setHead = nodes => {
if (_setHead) return _setHead(nodes)
app({
init: nodes,
view: nodes => nodes,
node: document.head,
middleware: d => (_setHead = d),
})
}
return app => defs => {
app({
...defs,
middleware: dispatch => (action, payload) => {
if (
typeof action !== 'function' &&
!Array.isArray(action)
) {
setHead(defs.head(action))
}
return dispatch(action, payload)
},
})
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment