GithubHelp home page GithubHelp logo

tiny-history's Introduction

tiny-history npm version Build Status

Build Status

tiny-history is a simple wrapper around the browser history API. To some extent it mimics the behaviour of history, a module created by the good folks from React Training. Main differences from it are that:

  • basename is not supported;
  • blocking transitions is not supported;

Why to use this

tiny-history's main selling point is it's size: ~500B minified and gzipped.

How to install

npm i tiny-history

# or

yarn add tiny-history

Browser builds are also available on unpkg:

<!-- iife -->
<script src=//unpkg.com/tiny-history/dist/tiny-history.js></script>

<!-- esm -->
<script type=module>
  import createHistory from "//unpkg.com/tiny-history/dist/tiny-history.esm.js";
  /* ... */
</script>

Usage

import createHistory from "tiny-history";

const history = createHistory();

function doSomething(location, action) {
  /* do something */
}

// register a listener for route transitions
const unlisten = history.listen(doSomething);

// push a new route
history.push("pushed");

// replace a route
history.replace("replaced");

// transition to the previous route
history.back();

// transition to the next route
history.forward();

// transition to an entry of the history based on the index passed
history.go(-1);

// history.listen returns a callback that detaches the listener passed to it
unlisten();

How to use tiny-history to replace history's createBrowserHistory

import createHistory from "tiny-history";

const history = createHistory();

history.goForward = history.forward;

history.goBack = history.back;

export default history;

LICENSE

MIT

tiny-history's People

Contributors

malbernaz avatar

Stargazers

Roman avatar Masahiro Miyashiro (3846masa) avatar André Araújo (Andrev) avatar Yuri Pereira Ramos avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.