API Docs for: 3.18.1

ModelSync.Local Class

Module: app

Available since 3.13.0

An extension which provides a sync implementation through locally stored key value pairs, either through the HTML localStorage API or falling back onto an in-memory cache, that can be mixed into a Model or ModelList subclass.

A group of Models/ModelLists is serialized in localStorage by either its class name, or a specified 'root' that is provided.

var User = Y.Base.create('user', Y.Model, [Y.ModelSync.Local], {
    root: 'user'
});

var Users = Y.Base.create('users', Y.ModelList, [Y.ModelSync.Local], {
    model: User,
});

Item Index

Methods

Properties

Methods

sync

(
  • action
  • [options]
  • [callback]
)

Creates a synchronization layer with the localStorage API, if available. Otherwise, falls back to a in-memory data store.

This method is called internally by load(), save(), and destroy().

Parameters:

  • action String

    Sync action to perform. May be one of the following:

    • create: Store a newly-created model for the first time.
    • read : Load an existing model.
    • update: Update an existing model.
    • delete: Delete an existing model.
  • [options] Object optional

    Sync options

  • [callback] Function optional

    Called when the sync operation finishes.

    • err Error | Null

      If an error occurred, this parameter will contain the error. If the sync operation succeeded, err will be falsey.

    • [response] Any optional

      The response from our sync. This value will be passed to the parse() method, which is expected to parse it and return an attribute hash.

Properties

root

String

Defined in app/js/model-extensions/model-sync-local.js:93

Available since 3.13.0

Root used as the key inside of localStorage and/or the in-memory store.

Default: ""

storage

Storage

Defined in app/js/model-extensions/model-sync-local.js:103

Available since 3.13.0

Shortcut for access to localStorage.

Default: null