tejacques / crosstab

A utility library for cross-tab communication using localStorage.
Apache License 2.0
364 stars 58 forks source link

becomeMaster vs tabPromoted vs tabUpdated #29

Closed moity closed 9 years ago

moity commented 9 years ago

I notice that the becomeMaster event doesn't seem to work as expected, it doesn't necessarily fire when a tab becomes master.

I also notice that your sample crosstab\samples\index.html doesn't use the becomeMaster event, instead it looks at the tabPromoted and tabUpdated events and updates the state of the UI (after a setTimeout) to the new state.

I would have thought the becomeMaster event would be the only event I would need to subscribe to for knowledge of who the master is (unless I specifically wanted to know when a tab was updated).

tejacques commented 9 years ago

becomeMaster only fires on the tab that is now turning into the master. tabPromoted is the event that's fired on every tab when a tab is promoted to master.

if you're trying to do some kind of resource setup, then becomeMaster is the right event to use.

moity commented 9 years ago

OK, cheers. I am trying to have one persistent connection to the server for realtime (signalr). Still need to check the initial state on page load as to whether the page is master or not as no becomeMaster will fire in that scenario right?

tejacques commented 9 years ago

becomeMaster event should always fire, but it's potentially possible that it's firing before you bind something to it.