npm.io
0.1.0 • Published 4 years ago

hyperapp-snapshot

Licence
Apache-2.0
Version
0.1.0
Deps
1
Size
15 kB
Vulns
0
Weekly
0

hyperapp-snapshot

Take and reproduce a snapshot of a hyperapp state as a JSON. Provides wrapView function to wrap your hyperapp application's view function to append two buttons to the view: save and load the state of the application as a JSON file.

Example

Run on Stackblitz

import { h, text, app } from 'hyperapp';
import * as Snapshot from 'hyperapp-snapshot';

const view = (model) =>
  h('main', {}, [
    // Your app view
  ]);

app({
  init: initialModel,
  view: Snapshot.wrapView(view),
  /* Or else:
  view: Snapshot.wrapView(view, JSON.parse)
  // You can optionally pass a JSON decoder function to convert the loaded
  // JSON string into the application's state type.
  */
  node: document.getElementById('app'),
});

Keywords