Why SAVE action dispatched with state not processed with engine? #135

Closed
opened 2016-05-09 21:08:04 +00:00 by nd0ut · 2 comments
nd0ut commented 2016-05-09 21:08:04 +00:00 (Migrated from github.com)

I was playing with redux-storage-decorator-filter and noticed that SAVE action comes with untouched state. I supposed to catch the action with the filtered state.

I imagine all this flow like that:
image

I mean I think the SAVE action should be dispatched with state processed with decorators.

But with the current architecture it's hard to catch state between decorators and engine. The easiest way is to catch it right from engine.

const dispatchSave = (state = getState()) => dispatch(actionSave);
engine.save(saveState).then(dispatchSave).catch(swallow);
I was playing with `redux-storage-decorator-filter` and noticed that `SAVE` action comes with untouched state. I supposed to catch the action with the filtered state. I imagine all this flow like that: ![image](https://cloud.githubusercontent.com/assets/670959/15126352/46ee867a-163a-11e6-9f71-c277943f9fe1.png) I mean I think the SAVE action should be dispatched with state processed with decorators. But with the current architecture it's hard to catch state between decorators and engine. The easiest way is to catch it right from engine. ``` javascript const dispatchSave = (state = getState()) => dispatch(actionSave); engine.save(saveState).then(dispatchSave).catch(swallow); ```
nd0ut commented 2016-05-09 21:31:24 +00:00 (Migrated from github.com)

Also I think it would be great to customize a save dispatcher
image
I'll make PR soon

Also I think it would be great to customize a save dispatcher ![image](https://cloud.githubusercontent.com/assets/670959/15128767/772501b4-1646-11e6-85a1-c6b50504988f.png) I'll make PR soon
michaelcontento commented 2016-06-12 18:44:44 +00:00 (Migrated from github.com)

Sorry for the very very delayed response! 😞

Yes, the state passed with the SAVE action is the whole state tree and not the actual part that has been saved by the engine. This is by done design and there are argument for both ways (passing the whole state or only the final slice).

If you want to track only the written slices (and, for example, other informations like the size in bytes or the duration) you can add a new decorator to the mix like:

// first we filter the state for this engine
import filter from 'redux-storage-decorator-filter'
engine = filter(engine, 'whitelisted-key');

// and now we add the telemetry decorator
import logEngineStatsDecorator from 'redux-storage-decorator-engine-logger';
engine = logEngineStatsDecorator(engine);

Would such a solution solve your needs?

Sorry for the very very delayed response! 😞 Yes, the state passed with the `SAVE` action is the whole state tree and not the actual part that has been saved by the engine. This is by done design and there are argument for both ways (passing the whole state or only the final slice). If you want to track only the written slices (and, for example, other informations like the size in bytes or the duration) you can add a new decorator to the mix like: ``` js // first we filter the state for this engine import filter from 'redux-storage-decorator-filter' engine = filter(engine, 'whitelisted-key'); // and now we add the telemetry decorator import logEngineStatsDecorator from 'redux-storage-decorator-engine-logger'; engine = logEngineStatsDecorator(engine); ``` Would such a solution solve your needs?
This discussion has been locked. Commenting is limited to contributors.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MichaelContento/redux-storage#135
No description provided.