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

dual-navigator

v0.1.0

Published

Route browser applications with dualapi

Downloads

2

Readme

dual-navigator ![Build Status](http://jenkins.plediii.net:8080/buildStatus/icon?job=dual-navigator master)

dualapi domains are already like a network of distributed HTTP servers extending into the browser. dual-navigator furthers this pattern by using the the window.location hash to route into a dualapi domain.

A live example is mounted at http://plediii.github.io/dual-navigator/example/index.html, for the routes at https://github.com/plediii/dual-navigator/blob/master/example/routes.js.

Using dual-navigator with dualapi

To use dual-navigator, first extend dualapi with the dual-navigator module:

var dualapi = require('dualapi').use(require('dual-navigator'));

Then once you've instantiated a dualapi domain,

var domain = dualapi();

you can create a navigator instance:

domain.navigator(window, {
    appRoute: ['app']
    , indexRoute: ['index']
    , globals: {}
    , cleanPage: function () {}
})

The declaration that states that:

  • The application routes can be reached on the domain below the ['app'] route.
  • If no route is provided, it will default to ['app', 'index'].
  • Between application states, the cleanpage function will be called (in this case a no-op)

Creating application routes

dual-navigator application routes are hosts which return functions to be called when the browser navigates to a window location with the same hash as the route:

domain.mount([app', 'index'], function (body, ctxt) {
   ctxt.return(function () {
     // render index application
   });
});

The application may optionally return a cleanup function, to be called before the next route is loaded.

domain.mount(['app', 'withcleanup'], function (body, ctxt) {
   ctxt.return(function () {
     // render index application
      return function () {
        // cleanup logic
      };
   });
});

Optional application specific cleanup

The cleanup function may optionally return a Promise to be resolved before continuing loading the next application. Finally, the optional cleanup function provided during navigator instantiation will be called, regardless of whether the app has its own cleanup function.

Normal navigator flow

The normal navigator flow is as follows:

  1. User navigates to a hash
  2. Navigator requests application
  3. Navigator calls previous application cleanup
  4. When the application cleanup resolves, navigator's cleanup
  5. When the cleanup complete, navigator calls the new application

See the example routes.