Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SyncStore

connects a Model/Collection to a Relution server.

This will give you an online and offline store with live data updates.

example

// The default configuration will save the complete model data as a json, // and the offline change log to a local WebSql database, synchronize it // trough REST calls with the server and receive live updates via a socket.io connection. class MyCollection extends Relution.livedata.Collection {}; MyCollection.prototype.model = MyModel; MyCollection.prototype.url = 'http://myServer.io/myOrga/myApplication/myCollection'; MyCollection.prototype.store = new Relution.livedata.SyncStore({ useLocalStore: true, // (default) store the data for offline use useSocketNotify: true, // (default) register at the server for live updates useOfflineChanges: true // (default) allow changes to the offline data });

Hierarchy

Hierarchy-Diagram

Index

Constructors

constructor

Properties

_type

_type: string

Protected credentials

credentials: any

Private disconnectedEntity

disconnectedEntity: string

when set, indicates which entity caused a disconnection.

This is set to an entity name to limit which entity may cause a change to online state again.

type

{string}

endpoints

endpoints: object

Type declaration

Protected entities

entities: any

isCollection

isCollection: boolean

isModel

isModel: boolean

isStore

isStore: boolean

Private lastMesgTime

lastMesgTime: any

Protected localStore

localStore: StoreCtor

Protected localStoreOptions

localStoreOptions: any

messages

messages: Collection

messagesPromise

messagesPromise: Promise<Collection>

Protected name

name: string

Protected orderOfflineChanges

orderOfflineChanges: string[]

Protected serverUrl

serverUrl: string

server associated with this store.

The sync method will fail early when being applied to data of some other server.

Protected socketPath

socketPath: string

Protected socketQuery

socketQuery: string

Protected trigger

trigger: trigger

Protected useLocalStore

useLocalStore: boolean

Protected useOfflineChanges

useOfflineChanges: boolean

Protected useSocketNotify

useSocketNotify: boolean

Protected userUuid

userUuid: string

identity or user associated with this store.

The ajax method will simulate an offline timeout when the user identity is changed. This is because just one session can be maintained per server and login/logout semantics must be well behaved.

Methods

Private _addMessage

  • Parameters

    Returns Promise<any>

Private _ajaxMessage

Private _applyResponse

_bindChannel

  • Parameters

    Returns void

Private _emitMessage

_fixMessage

Private _sendMessages

  • feeds pending offline #messages to the remote server.

    Due to client code setting up models one at a time, this method is called multiple times during initial setup of #endpoints. The first call fetches pending offline #messages, ordered by priority and time. Then the #messages are send to the remote server until depleted, an error occurs, or some missing endpoint is encounted.

    The method is triggered each time an endpoint is registered, or state changes to online for any endpoint. When state changes from offline to online (disregarding endpoint) message submission is restarted by resetting the #messagesPromise. Otherwise, subsequent calls chain to the end of #messagesPromise.

    Returns Promise<Collection>

    of #messages Collection, or last recent offline rejection

Private checkServer

  • checkServer(url: string, options?: any): Promise<string>
  • Parameters

    • url: string
    • Optional options: any

    Returns Promise<string>

clear

  • Parameters

    Returns void

close

  • close(): void
  • close the socket explicit

    Returns void

create

createLocalStore

  • Parameters

    Returns Store

createMsgCollection

  • description

    Here we save the changes in a Message local websql

    Returns Collection

createSocket

  • createSocket(endpoint: SyncEndpoint, name: string): Socket
  • Parameters

    Returns Socket

destroy

  • destroy(model: Model, options?: ModelDestroyOptions): void
  • Parameters

    • model: Model
    • Optional options: ModelDestroyOptions

    Returns void

fetch

  • fetch(collection: Model, options: ModelFetchOptions): Promise<any>
  • fetch(collection: Collection, options: CollectionFetchOptions): Promise<any>
  • Parameters

    • collection: Model

      usually a collection, but can also be a model

    • options: ModelFetchOptions

    Returns Promise<any>

  • Parameters

    • collection: Collection

      usually a collection, but can also be a model

    • options: CollectionFetchOptions

    Returns Promise<any>

Private fetchChanges

  • Parameters

    • endpoint: SyncEndpoint
    • Default value force: boolean = false

    Returns Promise<Collection>

Private fetchServerInfo

  • Parameters

    Returns Promise<Model>

getEndpoint

getLastMessageTime

  • getLastMessageTime(channel: string): any
  • Parameters

    • channel: string

    Returns any

Protected handleError

  • handleError(options: object, error: Error): any
  • Parameters

    • options: object
    • error: Error

    Returns any

Protected handleSuccess

  • handleSuccess(options: object, result: any): any
  • Parameters

    • options: object
    • result: any

    Returns any

initCollection

Protected initEndpoint

initModel

  • initModel(model: Model): void
  • Parameters

    Returns void

Private initServer

  • initServer(urlRoot: string): void
  • binds the store to a target server when the first endpoint is created.

    Parameters

    • urlRoot: string

      used to resolve the server to operate.

    Returns void

onConnect

  • Parameters

    Returns Promise<void>

onDisconnect

  • Parameters

    Returns Promise<void>

onMessage

Protected processOfflineMessageResult

  • processOfflineMessageResult(error: Error, message: LiveDataMessageModel, options: object): PromiseLike<void | any>
  • called when an offline change was sent to the remote server.

    May be overwritten to alter change message error handling behavior. The default implementation will attempt reloading the server data for restoring the client state such that it reflects the server state. When this succeeded, the offline change is effectively reverted and the change message is dropped.

    An overwritten implementation may decided whether to revert failed changes based on the error reported.

    Notice, the method is not called when the offline change failed due to a connectivity issue.

    Parameters

    • error: Error

      reported by remote server.

    • message: LiveDataMessageModel

      change reported, attributes of type LiveDataMessage.

    • options: object

      context information required to access the data locally as well as remotely.

    Returns PromiseLike<void | any>

    Promise indicating success to drop the change message and proceed with the next change, or rejection indicating the change message is kept and retried later on.

Private removeMessage

save

  • save(model: Model, attributes?: any, options?: ModelSaveOptions): any
  • Parameters

    • model: Model
    • Optional attributes: any
    • Optional options: ModelSaveOptions

    Returns any

setLastMessageTime

  • setLastMessageTime(channel: string, time: any): void
  • Parameters

    • channel: string
    • time: any

    Returns void

Private storeMessage

sync

  • sync(method: string, model: Model | Collection, options?: any): Promise<any>
  • Parameters

    • method: string
    • model: Model | Collection
    • Default value options: any = {}

    Returns Promise<any>

Generated using TypeDoc