Created
October 18, 2019 13:53
-
-
Save zaceno/6cbdc0128cc093b2a3026afd56e8f05f to your computer and use it in GitHub Desktop.
withHead hyperapp HOA
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 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