A 0.7 KB utility belt to build higher-order app
s (HOA) for Hyperapp v2 using middleware functions for onState
, onAction
, and onEffect
.
Install with npm / Yarn.
npm i hyperapp-middleware@next
Then with a module bundler like rollup or webpack, use as you would anything else.
import { withMiddleware } from "hyperapp-middleware"
Or using require.
const { withMiddleware } = require("hyperapp-middleware")
Download the minified library from the CDN.
<script src="https://unpkg.com/hyperapp-middleware@next"></script>
You can find the library in window.hyperappMiddleware
.
withMiddleware({
onState(nextState, prevState) {
// prevState will be undefined for initial state
},
onAction(action, state, props, data) {
// state is value before the action was processed
// props are from the [action, props] tuple, if used
// data is from second arg to dispatch, usually a DOM event
},
OnEffect(effect, state, props) {
// state will be whatever state was included in the tuple
}
})(app)({
// ... the usual suspects
})
Hyperapp Middleware is MIT licensed. See LICENSE.