aohua / redux-state-sync

A lightweight middleware to sync your redux state across browser tabs
MIT License
234 stars 28 forks source link

freezed action error #62

Open sayjeyhi opened 4 years ago

sayjeyhi commented 4 years ago

Redux saga advises that using freezed objects for actions in middleware :

io-427945dd.js:178 Error: You can't put (a.k.a. dispatch from saga) frozen actions.
We have to define a special non-enumerable property on those actions for scheduling purposes.
Otherwise you wouldn't be able to communicate properly between sagas & other subscribers (action ordering would become far less predictable).
If you are using redux and you care about this behaviour (frozen actions),
then you might want to switch to freezing actions in a middleware rather than in action creator.
Example implementation:

const freezeActions = store => next => action => next(Object.freeze(action))

but if we freeze our action object , sync state will gives this error :

TypeError: Cannot add property $uuid, object is not extensible
    at generateUuidForAction (syncState.js:59)
    at eval (syncState.js:139)
sayjeyhi commented 4 years ago

it point to this function, which add new properties on action :

function generateUuidForAction(action) {
  var stampedAction = action;
  stampedAction.$uuid = guid();
  stampedAction.$wuid = WINDOW_STATE_SYNC_ID;
  return stampedAction;
}
aohua commented 4 years ago

Hi @sayjeyhi, I Will need some time to figure this out.