https://github.com/coot/purescript-js-history
interface for browser history, plus memory history
https://github.com/coot/purescript-js-history
Last synced: 5 months ago
JSON representation
interface for browser history, plus memory history
- Host: GitHub
- URL: https://github.com/coot/purescript-js-history
- Owner: coot
- License: mit
- Created: 2017-03-10T17:54:30.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-07T22:21:11.000Z (about 9 years ago)
- Last Synced: 2025-03-01T03:41:32.633Z (over 1 year ago)
- Language: PureScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PureScript js history
The module provides a unified interface for managing histories using:
* browser history based on [`DOM.HTML.History`](https://pursuit.purescript.org/packages/purescript-dom/)
* memory history implemented using [`Ref`](https://pursuit.purescript.org/packages/purescript-refs)
There common type for them is
```purescript
type History e state =
{ state :: Eff (history:: HISTORY, dom :: DOM | e) (Maybe state)
, back :: Eff (history:: HISTORY, dom :: DOM | e ) Unit
, forward :: Eff (history:: HISTORY, dom :: DOM | e) Unit
, go :: Delta -> Eff (history:: HISTORY, dom :: DOM | e) Unit
, pushState :: state -> DocumentTitle -> URL -> Eff (history :: HISTORY, dom :: DOM | e) Unit
, replaceState :: state -> DocumentTitle -> URL -> Eff (history :: HISTORY, dom :: DOM | e) Unit
}
```
Note that if you want to use browser history `state` has to be an instance of
`IsForeign` and `AsForeign` classes.
The memory history also adds `addEventListener` function with a similar type to
the one you'd use when attaching events to the DOM. For the browser history
just use the `DOM.Event.EventTarget` module to attach events on the window object.