https://github.com/igrep/hyperapp-snapshot
Take and reproduce a snapshot of a hyperapp as a JSON
https://github.com/igrep/hyperapp-snapshot
Last synced: 5 days ago
JSON representation
Take and reproduce a snapshot of a hyperapp as a JSON
- Host: GitHub
- URL: https://github.com/igrep/hyperapp-snapshot
- Owner: igrep
- License: apache-2.0
- Created: 2022-01-13T02:00:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-13T07:23:03.000Z (over 4 years ago)
- Last Synced: 2026-01-29T21:14:09.484Z (6 months ago)
- Language: TypeScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://stackblitz.com/edit/typescript-rmfwbs?file=index.ts)
```ts
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'),
});
```