hyperapp-middleware

Build middleware for Hyperapp


Keywords
functional, higher-order, hyperapp, lifecycle
License
MIT
Install
npm install hyperapp-middleware@0.1.0

Documentation

Hyperapp Middleware

Build Status Codecov npm

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.

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")

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.