aohua / redux-state-sync

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

Prepare action 90 #135

Open rowrowrowrow opened 2 years ago

rowrowrowrow commented 2 years ago

@aohua This is a first take at something like a prepareAction function. Please let me know what you think. It addresses https://github.com/aohua/redux-state-sync/issues/90

aohua commented 2 years ago

Hi @rowrowrowrow Thanks for your PR, please also provide the use case on why you want to add this feature, thanks. Currently, I don't want to add too many new features, as I'm trying to refactor the code and redesign certain parts.

rowrowrowrow commented 2 years ago

@aohua Yep I understand about adding too many features. So from my perspective there are two ways that we can alter actions before they are shared with other windows.

  1. Dispatch an entirely new action. So if you want to share something you'd need to create a new action with a new 'type'. You have to account for both the original and the altered actions which can quickly add complexity.
  2. Allow modifying an action before it's sent. This is what the PR is for as I think it's simpler than option 1 above. This is analogous to the 'prepareState' function which specifically allows you to target modifying the initial state sent. I'm just arguing that we be able to do that for every action after initialization as well.

Please take a look at https://github.com/aohua/redux-state-sync/issues/90 for more explanation as to why you might need to modify an action. In my specific case I run into structured clone algorithm issues. Thanks!

rowrowrowrow commented 2 years ago

@aohua I also updated this PR as well. Thanks!

rowrowrowrow commented 2 years ago

Friendly reminder @aohua