Options
All
  • Public
  • Public/Protected
  • All
Menu

Available options for PersistentObject.

Options are passed to the constructor as plain object:

let store = new mar10.PersistentObject("test", {
  storage: sessionStorage,  // Default: localStorage
  attachForm: "#form1",
  defaults: {
    title: "foo",
    ...
  }
});

Events may be handled by passing a handler callback option:

let store = new mar10.PersistentObject("mySettings", {
  [...]
  change: function(hint){
    alert("Store " + this + " was changed. Reason: " + hint);
  }
});

Hierarchy

  • PersistoOptions

Index

Callback Properties

Optional change

change: undefined | ((hint: string) => void)

Called when data was changed (before comitting).

Optional commit

commit: undefined | (() => void)

Called after modified data was written to storage.

Optional conflict

conflict: undefined | ((remoteData: any, localData: any) => boolean)

Called when new data arrives from storage, while local data is still uncommitted.

Return false to prevent updating the local data with the new storage content.

Optional error

error: undefined | ((...args: any[]) => void)

Called on errors, e.g. when Ajax requests fails.

Optional pull

pull: undefined | ((response: any) => void)

Called after data was received from remote service.

Optional push

push: undefined | ((response: any) => void)

Called after modified data was POSTed to remote.

Optional save

save: undefined | (() => void)

Modified data was stored.

If remote was passed, this means push has finished, otherwise commit has finished.

Optional status

status: undefined | ((status: string) => void)

Status changed.

Possible values: 'ok', 'error', 'loading', 'status', 'modified'.

Optional update

update: undefined | (() => void)

Called after data was loaded from local storage.

Other Properties

Optional attachForm

attachForm: undefined | string | HTMLFormElement

Track form input changes and maintain persisto-STATUS class names.

  • Add class persisto to form.
  • Add and update persisto-STATUS class to form.
  • Call writeToForm on init, after data was loaded from storage (or backend).
  • Register event handlers to call readFromForm when users modify form data.
  • Handle submit and reset events to call readFromForm and prevent default.

commitDelay

commitDelay: number

Commit changes after X milliseconds of inactivity.

Commit cached changes to localStorage after 0.5 seconds of inactivity.
After each change, we wait 0.5 more seconds for additional changes to come in, before the actual commit is executed.

The maximum delay (first change until actual commit) is limited by maxCommitDelay.

Set to 0 to force synchronous mode. Default: 500 milliseconds.

Optional createParents

createParents: undefined | boolean

Allow PersistentObject.set to create missing intermediate parent objects.

Optional debugLevel

debugLevel: undefined | number

Verbosity level: 0:quiet, 1:normal, 2:verbose. Default: 1

Optional defaults

defaults: any

Default values if no data is found in localStorage.

Default: {}.

Optional maxCommitDelay

maxCommitDelay: undefined | number

Commit changes max. X millseconds after first change.

This settings limits the effect of commitDelay, which would otherwise never commit if the user enters keystrokes frequently.

Default: 3000 milliseconds

Optional maxPushDelay

maxPushDelay: undefined | number

Push commits max. X milliseconds after first change.

Push every commit to remote max. 30 seconds after it occurred. This setting limits the effect of pushDelay.

Default: 30000 milliseconds.

Optional pushDelay

pushDelay: undefined | number

Push commits after X milliseconds of inactivity.

Push commits to remote after 5 seconds of inactivity.
After each change, we wait 5 more seconds for additional changes to come in, before the actual push is executed.
The maximum delay (first change until actual push) is limited by maxPushDelay.

Set to 0 to force synchronous mode. Default: 5000 milliseconds

Optional remote

remote: any

URL for GET/PUT request to remote server.

Pass null to disable remote synchronization.
Default: null.

Optional statusElement

statusElement: undefined | string | HTMLFormElement

Set persisto-STATUS classes here.

Optional storage

storage: any

Instance of Web Storage.

Possible values are window.localStorage, window.sessionStorage.
Pass null to disable persistence.

Default: window.localStorage

Generated using TypeDoc