ModelSync.Local Class
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,
});
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
StringSync 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 optionalSync options
-
[callback]
Function optionalCalled when the sync operation finishes.
-
err
Error | NullIf an error occurred, this parameter will contain the error. If the sync operation succeeded, err will be falsey.
-
[response]
Any optionalThe 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
storage
Storage
Shortcut for access to localStorage.
Default: null