rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.96k stars 866 forks source link

transformers call order #1182

Open alpates opened 4 years ago

alpates commented 4 years ago

I am using two transformers one is the compressor and the other one is to convert date objects back and forth. The problem I am facing is the ordering if I place compressor at index "0" and data transform to "1" date transform is receiving compressed data. on outbound. When I swap them it receives compressed data on inbound. It seems to me what we have to swap call order between in and out cycles. Or I am missing something.

compress transformer

dateTransformer

export const dateTransformer = createTransform(
  data => JSON.stringify(data),
  toRehydrate =>
    JSON.parse(toRehydrate, (_key, value) =>
      typeof value === "string" &&
      value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)
        ? moment(value)
        : value,
    ),
);
{
  //...
  transformers: [compressor, dateTransformer],
}