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

routestate

v0.5.10

Published

RouteState is a flexible path router (designed for prototyping) that serializes it's state into the path as well as into the class of the body.

Downloads

659

Readme

RouteState

Synopsis

RouteState is a flexible path router (designed for prototyping) that serializes it's state into the path as well as into the class of the body. It has an event listening system as well as a way to tolerantly configure the path (it's optional and can easily be added at any time). This results in a very flexible state management system that enables you to layout and animate your UI almost entirely via CSS.

Installation

  1. add routestate to your package.json and install via script tag
  2. initiate RouteState with "listenToHash"
  3. (add configuration when you have a solid idea of your path)

Examples

// init
RouteState.listenToHash();

// Add a listener ( name of value, closure call back, and cluster id)
RouteState.addDiffListener(
    "page",
    function( route , prev_route ){
        // do something
    },
    "myPageName"
);
// In your HTML call (bind however you like):
<div onclick="RouteState.merge({page:'home'})">
    Go Home
</div>
<div onclick="RouteState.toggle({page:'home'},{last:''})">
    Toggle Page
</div>
<div onclick="RouteState.merge({'page.tab':'other'})">
    Change Tabs and connect existence of tab state to existence of page state
</div>
<div onclick="RouteState.merge({'page:tab':'other'})">
    Change Tabs and connect existence of tab state to existence of page and it's specific value when called
</div>
// Your hash will look like this:
// / values /{ names }[ dependencies(indexes) ]
#!/home/other{page,tab}[,0:]
// in this state:
// page = 'home' and tab = 'other'.
// tab is also dependent on page existing and page's value being 'home' ( b/c of added ":" )
<!-- ...and your body's class will look like this: -->
<body class="s_page s_page_home">

<!-- if you had a previous page: -->
<body class="s_page s_page_home sp_home sp_page_search">
/* Now construct your layout entirely in CSS */
/* (implies using LESS) */

.myHomePage {
    display: none;

    body.s_page_home & {
        display: block;
    }
}

/* ...or something with some animation */
.myHomePage {
    width: 0px;
    transition: width .3s;

    body.s_page_home & {
        width: 50%;
    }
}

/* ...or something more fancy */
.myHomePage {
    width: 0px;

    body.s_page_home & {
        width: 50%;
    }
    body.sp_page_search.s_page_home & {
        /* only animate when coming from search page... */
        transition: width .3s;
    }
}

// clean up when done...
RouteState.removeDiffListenersViaClusterId("myPageName");

// if you want to configure later...
var route_config = {
    page:{
        weight:10, // sort based on weight
        values:[ // have some idea of variations (doesn't restrict)
            "home",
            "search"
        ],
        show_in_hash:true, // show in the hash...keeps out of history
        show_in_body:true // show in the body
    },
    last:{
        weight:20,
        values:[],
        show_in_body:true,
        show_in_hash:false,
        dependency:"page"
    },
};
RouteState.config( route_config );
// for React...

componentWillMount: function(){
    var me = this;
    RouteState.addDiffListeners(
		["page","project"],
		function ( route , prev_route ) {
            me.forceUpdate();
		},
        "myPageName"
	);
},

componentWillUnmount: function(){
    RouteState.removeDiffListenersViaClusterId( "myPageName" );
},