aohua/redux-state-sync

How does initMessageListener work?

moubry opened this issue · 1 comments

I have a quick question about how initMessageListener is supposed to behave.

Let’s say I have a main window (Window 1) and then I open a new window/tab (Window 2). Currently, I’m seeing (via redux-logger) that &_INIT_MESSAGE_LISTENER is triggering:

  1. When Window 1 initially loads.
  2. When Window 2 initially loads.
  3. Again on Window 1 after Window 2 initially loads.

Why am I seeing 3?

Is it necessary for all other windows/tabs to re-init their message listener when new windows or tabs are created? If not, should I be putting &_INIT_MESSAGE_LISTENER in the backlist array?

To rephrase the question, what should I expect to break if I put &_INIT_MESSAGE_LISTENER in the backlist array?

This sentence is in the README of the project:

initMessageListener is a new function to fix the bug that if the other tab not triggering any action on first load, it cannot receive any messages.

Does ^ this mean that the new tab cannot receive messages from pre-existing tabs, or all other pre-existing tabs cannot receive messages from the new tab? Or both?

aohua commented

Good question. It should be ok to put it on the blacklist. Actually I should ignore it in the library itself. To create the message listener, it requires the dispatch function. It can be any action, but when the tab initialized, it needs to trigger any action to create the message listener to receive the actions that are triggered in other tabs.