0.2.0 • Published 7 years ago
hyperapp-middleware v0.2.0
Hyperapp Middleware
A 0.7 KB utility belt to build higher-order apps (HOA) for Hyperapp v2 using middleware functions for onState, onAction, and onEffect.
Installation
Node.js
Install with npm / Yarn.
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")Browser
Download the minified library from the CDN.
<script src="https://unpkg.com/hyperapp-middleware@next"></script>You can find the library in window.hyperappMiddleware.
API
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
})License
Hyperapp Middleware is MIT licensed. See LICENSE.