0.0.1 • Published 5 years ago

hyperload v0.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

Hyperload

npm

A higher-order app and component for dynamic import of Hyperapp v2 components. Requires support (or polyfill) for dynamic imports.

Installation

Node.js

Install with npm / Yarn.

Then with a module bundler like rollup or webpack, use as you would anything else.

import { withHyperload, Hyperload } from "hyperload";

Or using require.

const { withHyperload, Hyperload } = require("hyperload");

Browser

Download the minified library from the CDN.

<script src="https://unpkg.com/hyperload"></script>

You can find the library in window.hyperload.

Example

import { app, h } from "hyperapp";
import { withHyperload, Hyperload } from "hyperload";

const Loading = ({ error, otherProp }) => (
  <span>{error ? `Error! ${error}` : `loading ${otherProps}...`}</span>
);

const LoadMyComponent = Hyperload({
  // These are the required props
  module: "./my-component",
  loading: Loading,

  otherProps: "will be passed to the loading and resolved components"
});

withHyperload(app)({
  view: () => <LoadMyComponent />,
  container: document.body
});

Both the loading component and the dynamically imported module will receive the props that you pass to the Hyperload component. Errors encountered while importing your module will be passed to your loading component as the error prop.

License

Hyperload is MIT licensed. See LICENSE.