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

kahe

v0.7.4

Published

Minimal frontend framework for managing transition flow between application states.

Downloads

25

Readme

kahe

kahe (kā'-he) is a 2k client-side router built on ideas from page.js, bigwheel and ReactTransitionGroupPlus.

kahe's emphasis is on enabling animated transitions between pages or application states. Routes are mapped to views which support several lifecyle methods and are responsible for all rendering logic with the provided request data. Before and after hooks receive information about where the request is going, and were it's coming from.

Why kahe? Because it's the Hawaiian word for flow. And because nearly everything else is taken.

Installation

Install through npm or use as a standalone library with a script tag and one of the bundled files. Please message me if you're interested in a CDN version!

npm install kahe

Usage

import kahe from 'kahe';
import { Home, About, Project } from './views';

kahe.start({
  routes: {
    '/': Home,
    '/about': About
    '/projects/:slug': Project
  }
});

Options

Property | Default | Description ---------------- | -------- | ----------------------------------------- base | / | Base URL to use when resolving routes. routes | [] | an object mapping URL patterns to view function(s), or an array of routes config objects with path and view properties. These can also be defined using the route(path, config) method. before | null | A function or array of functions to be called before a transition begins. Each callback recieves a transition object with to and from properties representing the incoming and outgoing requests. after | null | A function or array of functions to be called after a transition completes. Each callback recieves a transition object with to and from properties representing the incoming and outgoing requests. transition | null | A string to specify the default transition flow (see transitions) or a function to be called before a transition begins.

Routes

Routes can be defined in several ways.

Using individual route() calls:

import { route, start } from 'kahe';

route('/', Home);
route('/about', About);
route('/projects/:slug', Project);

// start resolving routes
start();

Using a routes array:

kahe.start({
  routes: [
    {path: '/', view: Home},
    {path: '/about', view: About},
    {path: '/projects/:slug', view: Project}
  ]
});

Using a routes object:

kahe.start({
  routes: {
    '/': Home,
    '/about': About
    '/projects/:slug': Project
  }
});

Views

Views are functions or objects that optionally implement the following lifescyle methods:

  • init
  • resize
  • animateIn
  • animateOut
  • destroy

The init, animateIn and animateOut methods receives two arguments: req and done. req is an object representing request data, including captured url params. The resize method is called immediately before animateIn and recieves the current window width and height as arguments. Use the destory method to run cleanup work such as removing DOM nodes or event listeners.

Transitions

Transitions manage the flow between application states and are what make kahe unique. Inspired by ReactTransitionGroupPlus and the once popular Gaia Framework for Flash, transitions come in three types which control the order at which lifecycle methods are called on incoming and outgoing views.

normal

Transitions are synchronous.

  • incoming.init(req, done)
  • incoming.animateIn(req, done) and outgoing.animateOut(req, done)

out-in

  • incoming.init(req, done)
  • outgoing.animateOut(req, done)
  • incoming.animateIn(req)

in-out

  • incoming.init(req, done)
  • incoming.animateIn(req, done)
  • outgoing.animateOut(req, done)

With all transition types, if another URL is requested while a transitio is in progress, it will be queued and executed imediately after the current transition completes.

API

route(path[, config]);

Adds a route definition if both path and config are specificed. Route config optinos can be a single object representing a view function, an array of view functions or objects or an object containing a view property (object or array). The advantage of the last option is being able to add custom route meta that gets merged with the request object. Example:

route('/', {view: Home, name: 'home'});
route('/photos/:category', {view: Gallery, name: 'gallery'});

Calling route with only a string with navigate to the given URL. This is called internally by the framework when a link is clicked, but can be useful to programmatically change states. ~~~Optionally pass {replace: true} to update the current window.history record rather than pushing a new entry onto the stack.~~~

before(transition);

after(transition);

start(options);

Start the framework and begin resolving routes.

Browser Support

kahe uses Promises to handle transition flow, which means a polyfill would be required for IE11 and below.

Development

Unit tests (which are incomplete!) use budo, tape and tap-dev-tool (for more readable output).

npm install -g budo
npm install
npm run test