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

How Can I rehydorate model class extended Immustable.Record #39

Open
Yoshihide-Nishimoto opened this issue Mar 13, 2020 · 1 comment
Open

Comments

@Yoshihide-Nishimoto
Copy link

How Can I rehydorate model class extended Immustable.Record

This is part of my code.(don't work properly)

my model

export interface IUsers {
  users: List<IUser>;
}
export const UsersRecord = Record<IUsers>(
  {
    users: List(),
  },
  'UsersRecord',
);
export class UsersModel extends UsersRecord{
  addUser() {
      return this.set(
        'users',
        this.users.push(new UserRecord({name: 'test user'})),
    );
  }
}

my store configure

export const createRootReducer = () =>
  combineReducers({
    auth: authReducer,
    users: usersReducer,
  });

const persistConfig = {
  key: 'root',
  storage: AsyncStorage,
  transforms: [
    immutableTransform({
      users: [UsersRecord],
    }),
  ],
};

const persistedReducer = persistReducer(persistConfig, createRootReducer());

handle model instance

  return Object.assign({}, state, {users: state.users.addUser()});

warning

TypeError: state.users.addUser is not a function

It seems redux-persist not restore the users as UsersModel, but

Before implementing redux-persist, state.users.addUser was a function object,and worked fine.
Could you help me??

    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-redux": "^7.2.0",
    "redux-persist-transform-immutable": "^5.0.0",
    "redux-persist": "^6.0.0",
@tusharmutreja200
Copy link

@Yoshihide-Nishimoto Hey did you find any resolution, I am facing the same issue

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

No branches or pull requests

2 participants