Version 3.17.2

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,



() protected

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

Available since 3.13.0

Sync method correlating to the "delete" operation. Deletes the data from the in-memory object, and saves into localStorage if available.


() Object[] protected

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

Available since 3.13.0

Sync method correlating to the "read" operation, for a Model List



Array of objects found for that root key


() protected

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

Available since 3.13.0

Saves the current in-memory store into a localStorage key/value pair if localStorage is available; otherwise, does nothing.


() Object protected

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

Available since 3.13.0

Sync method correlating to the "read" operation, for a Model



Object found for that root key and model ID


() Object protected

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

Available since 3.13.0

Sync method correlating to the "create" operation



The new object created.


() Object protected

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

Available since 3.13.0

Sync method correlating to the "update" operation



The updated object.


  • pre

Generate a random GUID for our Models. This can be overriden if you have another method of generating different IDs.


  • pre String

    Optional GUID prefix


  • 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().


  • 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.



Object private

Object of key/value pairs to fall back on when localStorage is not available.


Boolean private

Feature testing for localStorage availability. Will return falsey for browsers with localStorage, but that don't actually work, such as iOS Safari in private browsing mode.


Array protected static

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

Available since 3.13.0

Properties that shouldn't be turned into ad-hoc attributes when passed to a Model or ModelList constructor.

Default: ['root']


Array private

Cache to quickly access a specific object with a given ID.



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: ""



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

Available since 3.13.0

Shortcut for access to localStorage.

Default: null