# occamsrazor-history-browser

> it bridges the browser history API with occamsrazor events

Latest version **0.0.3** (published 2017-12-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install occamsrazor-history-browser
pnpm add occamsrazor-history-browser
yarn add occamsrazor-history-browser
bun add occamsrazor-history-browser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2017-12-19 |
| First published | 2017-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maurizio Lupo |
| Maintainers | sithmel |
| Keywords | events, history |

## Links

- npm: https://www.npmjs.com/package/occamsrazor-history-browser
- Repository: https://github.com/sithmel/occamsrazor-history-browser
- Homepage: https://github.com/sithmel/occamsrazor-history-browser#readme
- Issues: https://github.com/sithmel/occamsrazor-history-browser/issues
- npm.io page: https://npm.io/package/occamsrazor-history-browser

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2017-12-19
- 0.0.2 — 2017-12-19

## README

occamsrazor-history-browser
===========================
This function provides a bridge between the history API and the event bus created using [occamsrazor](https://github.com/sithmel/occamsrazor.js)
It exposes a convenient "changestate" event that fires when pushstate/replacestate are called or popstate event is triggered.
See the [history API](https://developer.mozilla.org/en-US/docs/Web/API/History_API)
```js
var or = require('occamsrazor');
var registerHistoryAPI = require('occamsrazor-history-browser');

var events = or();
registerHistoryAPI(events);

events.on('changestate', function (evt, newState) {
  // either pushstate was triggered on "events"
  // or popstate fired on "window". For example the user clicked back or forward
});

events.trigger('pushstate', { state: { ... }, title: 'newTitle', url: 'new.html' });
```

Syntax:
**registerHistoryAPI(events, window);**

* events: an occamsrazor instance
* window (optional): the global object, it defaults to "window"

You can interact with the history API using 2 events: **pushstate** and **replacestate**.
They takes as second argument an object with state, title, url: the arguments are then passed to history.pushstate or history.replacestate.

These events trigger 'changestate' that is called with the new state. changestate is also called by the browser when popstate is triggered (clicking the back button for example).

---
_Source: https://npm.io/package/occamsrazor-history-browser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
