Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immutable.js support #15

Closed
wants to merge 4 commits into from
Closed

Conversation

magne4000
Copy link

@magne4000 magne4000 commented May 17, 2017

Add support for Immutable.js.
Also makes non Immutable.js state modifications immutable (with spread operator) (see #4).

With this, I can migrate a basic store to an Immutable.js one

import createMigration from 'redux-persist-migrate';
import Immutable from 'immutable';

// these keys won't be persisted
export const blacklist = [
  'dummy'
];

function fromJSGreedy(js) {
  if (typeof js !== 'object' || js === null) {
    return js;
  }
  if (Immutable.Iterable.isIterable(js)) {
    return js.map(fromJSGreedy);
  }
  if (Array.isArray(js)) {
    return Immutable.Seq(js).map(fromJSGreedy).toList();
  }
  return Immutable.Seq(js).map(fromJSGreedy).toMap();
}

export const manifest = {
  1: state => fromJSGreedy(state).toObject() // payload must be an object
};

const reducerKey = 'app';
export const migration = createMigration(manifest, reducerKey);

@magne4000 magne4000 closed this Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant