maxdeviant/redux-persist-transform-encrypt

post-serialize transforms

rt2zz opened this issue · 3 comments

rt2zz commented

Hey @maxdeviant, I noticed for this transform as well as the compress transform we need to serialize the state before transforming it. This leads to potentially multiple serializations, which while not terrible since stringifying a string is super cheap, it is not ideal.

Any thoughts on how to solve this? The simplest albeit ugly solution would be to split out transforms into preSerializeTransforms, postSerializeTransforms. Another option would be to require a serialize transform before the encrypt/compress like this: transforms: [serialize, encrypt] and then throw an error if encrypt receives non-serialized data.

Thoughts?

Does it serialize multiple times?

I know I only call stringify if the incoming data is not already a string.

But out of the two proposals, I think I like the second one more, since it seems like it would ultimately be more composable.

rt2zz commented

@maxdeviant it is unfortunate to make every transform that works on strings implement conditional stringify. But I suppose that is better than an ugly api. 👍