Storage

This section describes the Cookie and Depot objects and methods. Each section includes a brief description, repeating some of the information from Chapter 6, followed by an enumeration of each object’s methods with their arguments and return values. Both storage objects are accessed through a direct API, so the format for this entry will be structured as an API entry.

If you’d like more detailed information on the HTML 5 Database object, refer to the specification at http://dev.w3.org/html5/webstorage/#databases.

Mojo.Model.Cookie()

Mojo cookies are technically related to browser cookies, but with an object interface to simplify use by webOS applications. Mojo cookies typically store small amounts of data that will be used to preserve application state and related information, such as preference settings.

Calling the constructor will open the named cookie if it already exists, or if it doesn’t exist, will create it.

Constructor

new Mojo.Model.Cookie(cookieName, optionalDocument)

Arguments

Type

Description

cookieName

String

Name for the cookie; has an application scope so uniqueness across applications is not a requirement

optionalDocument

Object

Document element to store cookie; defaults to current document

Methods

get()

Returns the object stored in this cookie, or undefined if the cookie doesn’t exist

put(objectToStore, expirationDate)

Updates the value of this cookie with the passed object with an optional date object to set an expiration date; if no expiration date is set, the cookie will not expire

remove()

Deletes the cookie

Mojo.Depot()

The Depot object is a wrapper on the HTML 5 APIs for simple object storage and retrieval. You can store up to 1 MB of data in a depot by default. Mojo provides by a few simple functions that wrap the HTML 5 APIs to create, read, update, or delete a database.

Calling the constructor will open the named depot if it already exists, or if it doesn’t exist, will create it.

Constructor

new Mojo.Depot(options, onSuccess, onFailure)

Arguments

Type

Description

options

Object

Options for opening or creating a depot, structured as:

  name

String

Name used to identify the underlying database; has an application scope; use 'ext:' prefix to create Depot in the /media partition

  version

Integer

Version number used for the underlying database

  displayName

String

Not currently supported; for future use

  estimatedSize

Integer

Estimated size in bytes; used to assist framework in managing databases

  replace

Boolean

If true, will replace the existing database if it exists; defaults to false

onSuccess

Function

Callback function that is called if the depot is successfully opened or created

onFailure

Function

Callback function that is called with an error string if an error occurs

Methods

add(key, objectToStore, 
onSuccess, onFailure)

Function to add an object, objectToStore, identified by a key

get(key, onSuccess, 
onFailure)

Gets the object identified by the key and returned as the single argument to the onSuccess function

discard(key, onSuccess, 
onFailure)

Removes the depot object associated with the key

removeAll(onSuccess, 
onFailure)
Removes everything in the depot
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.102.195