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

@yeldirium/redux-migrations

v1.2.6

Published

A redux enhancer supporting migrations for persisted state.

Downloads

11

Readme

Redux Migrations

This package is no longer maintained.


A utility for creating redux stores and migrating existing data to the new store's structure.

npm install @yeldirium/redux-migrations
# or
yarn install @yeldirium/redux-migrations

Status

| Category | Status | | ---------------- | ----------------------------------------------------------------------------------------------------------------------------- | | Version | npm | | Dependencies | David | | Dev dependencies | David | | Build | GitHub Actions | | License | GitHub |

Why?

If you use redux to maintain your application's state and persist that state in some way across application starts - be it with a database or a json file - you will at some point run into the problem that your store structure changes. Maybe a new store branch is added or some reducer layers are restructured - migrations are necessary when the persisted state is not usable by a new version of the application anymore.

How?

This project draws inspiration from a migration solutions like doctrine migrations in the way it tracks executed migrations. It adds a store branch for migrations to your applications store (which you cannot modify) in which it keeps track of the ids of executed migrations, so that only new ones are executed.

Migrations will never run multiple times and redux-migrations will tell you if your migration definitions don't match the persisted state.

Use it like so:

const { createStore } = require("redux");
const { migrations } = require("redux-migrations");

const reducer = require("...your reducer");
const fetchStateFromSomewhere = require("...wherever you persist your state");

const migrationDefinitons = [
  {
    id: "12345",
    migrate: state => ({
      ...state,
      newBranch: []
    })
  },
  {
    id: "4895",
    migrate: ({ newBranch, ...restState }) => ({
      ...restState,
      nested: {
        newBranch,
        anotherNewBranch
      }
    })
  }
];

const preloadedState = await fetchStateFromSomewhere();

const store = createStore(
  reducer,
  preloadedState,
  migrations(migrationDefinitions)
);

After all that, the migrations are executed on the preloaded state (if they haven't been before) and the state in the newly created store should have the form you want.

API

migrations(...migrationDefinition): Enhancer

Takes a list of migrations definitions of the form

const migrationDefinition = {
  // Some string identifier. choose it however you like. timestamps or uuids are recommended
  id: "1234",
  migrate: state => {
    return modifyState(state);
  }
};

and returns a redux enhancer.