npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

behave-history

v0.1.4

Published

A better browser history manager

Downloads

15

Readme

behave-history

A better browser history manager

Codeship Status for behavejs/behave-history

In most other frameworks, history management is directly tied to your routers. This violates the single responsibility rule and tightly couples two large components of the application together. Proper history management is now more important than ever, and having routers that you feel comfortable with is equally important. The only requirement to use behave-history is that you pass it a dispatcher on initialization. (Don't sweat, you don't have to be using the Flux/React style of architecture, there will be examples with other architectural patterns.)


Installation

npm install --save behave-history

Usage

var dispatcher = require('behave-dispatcher'),
    BehaveHistory = require('behave-history');

/* in app initialization code */
var history = new BehaveHistory({
    // if app does not live at root of site update to app root
    root: '/',

    // pushState is default, use if you need to support IE8
    // URLs will have `#/` prefix
    hashChange: false,

    // event type to listen for to update history
    // also event type given to dispatcher when url changes from outside app
    eventType: 'ROUTE_CHANGE',

    // must have a `register` and a `dispatch` method
    // register method must take two params: 1) ID for callback, 2) callback
    // integrates directly with `behave-dispatcher`
    dispatcher: dispatcher
});

// you can start and stop history at any point
// history will ignore any dispatcher/window events unless started
history.start();

myApp.history = history;

/* NOTE: you must handle page load routing yourself */
myApp.on('start', () => {
    dispatcher.dispatch({
        type: 'ROUTE_CHANGE',
        route: window.location.pathname,
        data: {},
        options: {}
    });
});

History just dispatches an event on the passed in dispatcher, meaning you can initialize routers at any time during the application life-cycle.

This integrates seemlessly with any type of dispatcher or event system, you may need to do a thin layer of integration but this history module can be used in any application.

behave-history has a fantastic feature in modern browsers, any evt.data passed to a routing dispatch event will be set using pushState, meaning as users navigate backward and forward with the browser buttons, the dispatcher event fired will have a copy of that state at that moment in time. Allowing you to easily recreate previous states of your application. (evt.data will be an empty object if using hashChange or there is no data associated with current state).


Testing

Simply run npm install and then npm test


Release History

  • 0.1.0 Initial Release
  • 0.1.1 Updated readme and updated npm keywords
  • 0.1.2 Added build badge
  • 0.1.3 Moved away from same event for route and route change
  • 0.1.4 Added new build