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

redux-route

v0.0.3

Published

Ideomatic routing for Redux

Downloads

40

Readme

Redux Route

How would you implement routing if the address bar was just a regular input element?

Build Status

By default redux-route uses the addressbar module which makes the window's location behave like any other input field.

On top of that it uses the awesome url-pattern library to perform the matching.

With this combination it's very simple to keep all the routing information inside the redux state which should be you application's single source of truth:

import { createRouter, routeReducer } from 'redux-route';

const router = createRouter({
  home: '/',
  items: '/items/(:id)'
});

const rootReducer = combineReducers({
  route: routeReducer,
  // other reducers ...
});

// Dispatch actions when the URL changes:
router.connectToStore(store);

The redux state will now provide routing information under the key you chose. If /items/23 was requested state.route would be:

{
  path: '/items/23',
  params: { id: 23 },
  name: 'items'
}

Component Selection

Use state.route.name to select which top-level component you want to display. Instead of a switch statement you can also use the selectComponent helper:

import { selectComponent } from 'redux-route';

const mapStateToProps = selectComponent({
  home: (params, path) => <Home />,
  NO_MATCH: () => <Error />
});

connect(mapStateToProps)(Component);

Adapters

Redux-route provides several adapters to obtain or modify the actual location:

  • hash: Uses location.hash and hashchange events and also works in legacy browsers.
  • addressbar: Uses the addressbar module.
  • auto: Uses addressbar if supported and falls back to hash. This is the default.
  • fixed: A static URL for server-side routing. Requires no DOM.

The adapter interface is very simple so you can provide your own implementation to match your needs.

Credits

Thanks to Arnaud Rinquin for writing redux-reroute. This project started as a fork of his awesome work and the example app is still pretty much the same.

Thanks to Christian Alfoni for making addressbar such a generic and standalone module.

Thanks to Callum Jefferies for redux-routing which is another awesome routing library that with its universal routing support inspired me to go with the adapters approach.

Thanks to Maximilian Krüger for writing url-pattern which made it really easy to turn all the ideas into a lightweight router.

License

MIT