2.0.6 • Published 4 years ago

hyperapp-auto-history v2.0.6

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

HyperApp Auto History

tl;dr: Keeps some fields in your state object in-sync with the browser's URL bar. Changing the state changes the URL, changing the URL changes the state. You can copy-paste the URL to somebody, so that not only do they see the same page, but they also see the same data inside the page :D

If the page is loaded with no hash, populate it with default settings. If the page is loaded with a hash, load our initial settings from there.

For apps who only care about "what page is the user viewing", it's probably nicer to use a router plugin which looks at the whole url, so that the user sees mysite.com/cats where this plugin would give mysite.com/#{"page":"cats"}. But if you want to have multiple state variables in the URL, this can work :)

Args:

  • push: a list of attribute names; when any of these change, a new history entry is pushed
  • replace: a list of attribute names; when any of these change, replace the current history entry

See demo.html for an interactive demo

Usage:

import { AutoHistory } from "hyperapp-auto-history";

let state = {
    page: "track_list",
    selected_track: null,
    search: "",
    track_list: [
      {title: "Best Cat", artist: "Ciri"},
      {title: "Test Data", artist: "The Examples"},
      {title: "My Cat", artist: "Bonobo"},
    ],
};

app({
    init: state,
    subscriptions: (state) => [
        AutoHistory({
            push: ["page", "selected_track"],
            replace: ["search"],
        }, state)
    ],
})
2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.16

4 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago