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-react-router-transitions

v0.3.0

Published

Define transitions based on actions

Downloads

33

Readme

redux-react-router-transitions

Router transitions based on arbitrary actions.

This store enhancer allows you to co-locate transitions next to your actions and have them automatically executed on your router instance, after the action has been dispatched.

Why?

A typical case is that you want to redirect your user to another page, when they log in. There are multiple ways of doing this. You could for example listen to your store and perform a transition based on some kind of loginSuccessful flag. But this type of flag is something that does not actually belong into your state, as it is only used as an internal flag so you know when to transition.

Another way would be to use something like RX, and listen to distinct state changed, so you could transition your user to a page, whenever the loggedIn or user prop on your state changes.

While these approaches work, they make it hard to connect a transition to a specific action. Your transitions are also spread out over your code. redux-react-router-transitions allows your to embed your transitions directly within your actions and have them executed after your action has been dispatched.

Usage

Create an enhanced store like this:

import { createStore, compose } from 'redux';
import storeEnhancer from 'redux-react-router-transitions';

// you have to create your router here and pass it to the store enhancer

const finalCreateStore = compose(
  storeEnhancer(router)
)(createStore);

Now you can dispatch actions in the following form and have your desired transition automatically executed for you:

// we expect `LOGGED_IN` to have been imported here from your action constants

export default {

  login() {
    return {
      type: LOGGED_IN,
      payload: {
        userId: 123
      }
      meta: {
        transition: (state, action) => ({
          path: '/logged-in/:userId',
          query: {
            some: 'queryParam'
          },
          params: {
            userId: action.payload.userId
          }
        })
      }
    };
  },
}

Now every time you dispatch your login action, a transition to /logged-in will happen automatically. Of course query and params are optional. They are just here to show a complete example.

API

coming soon

Example

For a working example check out the example directory!

Running the example app

git clone https://github.com/johanneslumpe/redux-react-router-transitions.git
cd redux-react-router-transitions
npm install

cd example
npm install
npm start
open http://localhost:3000

FAQ

Why is this a store enhancer and not a middleware?

Because the transition handlers should receive the state after the action has been dispatched. And I did not want to use something like _.defer.

Does this work with react-router 1.0?

Not currently, but there is a pending PR which will make the 1.0 branch much more modular. After that PR is merged this should work flawlessly.

Can I perform replaceWith transitions instead of transitionTo?

Yes, just add replace: true to the object returned by your action's meta.transition function.