Page MenuHomeGitPull.it

class JX.Leader
Javelin Documentation ()

Synchronize multiple tabs over LocalStorage.

This class elects one tab as the "Leader". It remains the leader until it is closed.

Tabs can conditionally call a function if they are the leader using callIfLeader(). This will trigger leader election, and call the function if the current tab is elected. This can be used to keep one websocket open across a group of tabs, or play a sound only once in response to a server state change.

Tabs can broadcast messages to other tabs using broadcast(). Each message has an optional ID. When a tab receives multiple copies of a message with the same ID, copies after the first copy are discarded. This can be used in conjunction with callIfLeader() to allow multiple event responders to trigger a reaction to an event (like a sound) and ensure that it is played only once (not once for each notification), and by only one tab (not once for each tab).

Finally, tabs can register a callback which will run if they become the leading tab, by listening for onBecomeLeader.

Tasks

Builtin Events

  • invoke(type, more) โ€” Invoke a class event, notifying all listeners. You must declare the events your class invokes when you install it; see @{function:JX.install} for documentation. Any arguments you provide will be passed to listener callbacks.
  • static listen(type, callback) โ€” Static listen interface for listening to events produced by any instance of this class. See @{method:listen} for documentation.

Other Methods

Methods

invoke(type, more)
Inherited

JX.Base

Invoke a class event, notifying all listeners. You must declare the events your class invokes when you install it; see JX.install() for documentation. Any arguments you provide will be passed to listener callbacks.

Parameters
stringtypeEvent type, must be declared when class is installed.
...moreZero or more arguments.
Return
JX.EventEvent object which was dispatched.

static listen(type, callback)
Inherited

JX.Base

Listen for events emitted by this object instance. You can also use the static flavor of this method to listen to events emitted by any instance of this object.

See also listen() in JX.Stratcom.

JX.Base

Static listen interface for listening to events produced by any instance of this class. See listen() for documentation.

Parameters
stringtypeType of event to listen for.
functioncallbackFunction to call when this event occurs.
Return
objectA reference to the installed listener. You can later remove the listener by calling this object's remove() method.

private static _markSeen(id)

This method is not documented.
Parameters
id
Defined
lib/Leader.js:37
Extends
JX.Base