Home Reference Source Repository

Function

Static Public Summary
public

cookiesync(key: string, action: function, handler: function): Object

Creates a synchronizer which uses cookie polling to transmit objects to other tabs.

public

localsync(key: string, action: function, handler: function): Object

Creates a synchronizer which uses localStorage 'storage' event for synchronization between tabs.

Static Public

public cookiesync(key: string, action: function, handler: function): Object source

import cookiesync from 'localsync/lib/cookiesync.js'

Creates a synchronizer which uses cookie polling to transmit objects to other tabs.

Params:

NameTypeAttributeDescription
key string

The key to synchronize on.

action function

The action to run when trigger is executed. Should return the payload to be transmitted to the handlers on other tabs.

handler function

The handler which is executed on other tabs when a synchronization is triggered. Argument is the return value of the action.

options.tracing boolean
  • optional
  • default: false

Option to turn on tracing for debugging.

options.logger Object
  • optional
  • default: console

The logger to debug to.

options.logLevel string
  • optional
  • default: info

The log level to trace at.

options.idLength number
  • optional
  • default: 8

The number of characters to use for unique instance ID.

options.pollFrequency number
  • optional
  • default: 3000

The frequency (in milliseconds) to poll at.

options.path string
  • optional
  • default: '/'

The path to store the cookie at.

options.secure boolean
  • optional
  • default: false

Flag to set the cookies secure flag.

options.httpOnly boolean
  • optional
  • default: false

Flag to set the cookies httpOnly flag.

Return:

Object

cookiesync instance with start, stop, trigger, isRunning, isFallback, and instanceID properties.

public localsync(key: string, action: function, handler: function): Object source

import localsync from 'localsync/lib/localsync.js'

Creates a synchronizer which uses localStorage 'storage' event for synchronization between tabs.

Params:

NameTypeAttributeDescription
key string

The key to synchronize on.

action function

The action to run when trigger is executed. Should return the payload to be transmitted to the handlers on other tabs.

handler function

The handler which is executed on other tabs when a synchronization is triggered. Argument is the return value of the action.

options.tracing boolean
  • optional
  • default: false

Option to turn on tracing for debugging.

options.logger Object
  • optional
  • default: console

The logger to debug to.

options.logLevel string
  • optional
  • default: info

The log level to trace at.

Return:

Object

localsync instance with start, stop, trigger, isRunning, and isFallback properties.