rt2zz / redux-persist-transform-immutable

immutable support for redux-persist
112 stars 42 forks source link

transform-immutable not working with transform-encrypt (v5 issue) #35

Open Flollipop opened 6 years ago

Flollipop commented 6 years ago

Hi,

I facing some issues to use transform-immutable and transform-encrypt with redux-persist v5.

I managed to use transform-immutable alone.

But when I try to use encrypt with it I get some issues.

in the persist's config file:

const persistConfig = {
   transforms: [ encryptor, immutableTransform() ],
   key: 'root',
   storage: storage,
   debug: true
};

Give an object state (immutable not working when get data from storage). It's like immutableTransform return exactly what it get from encryptor.

So it seems when writing transform-encrypt accept transform-immutable data but when reading immutable-transform does nothing.

const persistConfig = {
    transforms: [ immutableTransform(),  encryptor],
    key: 'root',
    storage: storage,
    debug: true
};

Give an empty state after attempting rehydratation.

If found some old related issues, but seems code is not the same now. https://github.com/maxdeviant/redux-persist-transform-encrypt/issues/2

An idea where the conflict between this two package can be? Is it relevant to update encrypt or immutable, or create an transform between this two?

Thank you for your work.

Flollipop commented 6 years ago

In the first time I've tried a dumy custom temporary transform between encrypt and immutable, pending v5 support

const myV4ToV5Transform = createTransform( 
    (inboundState, key) => JSON.parse(inboundState),

    (outboundState, key) => JSON.stringify(outboundState)
);

const persistConfig = {
    transforms: [ immutableTransform(), myV4ToV5Transform, encryptor ],
    key: 'root',
    storage: storage,
    debug: true
};

after some reflexion I came with this solution using immutable functions, to completely replace immutable Transform.

export const myImmutableTransform = createTransform(
    (inboundState) => inboundState.toJS(),

    (outboundState) => fromJS(outboundState),

    { blacklist: [ '_persist' ] }
);