Class: RemoteStore

RemoteStore

new RemoteStore(options, data)

RemoteStore implementation of the Spark Framework. Makes HTTP GET, POST PUT or DELETE request to manage the data on the server. Use fetch to get or update the data, use save to write data back to server or remove to delete the data from the server.

Parameters:
Name Type Argument Description
options Object <optional>

Class options.

data * <optional>

Class data

Source:

Extends

Members

<static> EventTypes :string

Emitted event types.

Type:
  • string
Properties:
Name Type Default Description
SAVED string Saved
SAVE_FAILED string SaveFailed
FETCHED string Fetched
FETCH_FAILED string FetchFailed
REMOVED string Removed
REMOVE_FAILED string RemoveFailed
Source:

Methods

clear()

Removes all keys from store.

Inherited From:
Source:

destroy()

Destroys the object. Emits the following events before and after the object is destroyed. Sets data and options to null and calls the dispose and disposeInternal on parent to make a proper clean up. Calling dispose will set the Object.isDisposed to true and calling disposeInternal will unlisten all binded events so there won't be any event and/or memory leak.

Inherited From:
Source:

emit(eventName, data)

Dispatches an event and calls all listeners listening for events of this event. See also goog.events.Listenable.prototype.dispatchEvent

Parameters:
Name Type Argument Description
eventName string

Name of the event.

data * <optional>

Data which will passed to listeners

Inherited From:
Source:

fetch(callback)

Fetches the store data from server. Uses idKey property to find the store on the server. You can use fetch to populate the store from the server or when you want to update store data with latest data on the server. Callback is optional. Depending the result EventTypes.FETCHED or EventTypes.FETCH_FAILED events will be triggered.

Parameters:
Name Type Argument Description
callback function <optional>

Callback function to handle the request.

Source:

freeze()

Freezes object to prevent adding new properties, updating or deleting existing properties.

Inherited From:
Source:

get(key, escape) → {*}

Returns value of the given key from the store. String values will be encoded by default to prevent possible XSS attacks. If you don't want the encoding for some reason pass a second false parameter.

Parameters:
Name Type Argument Description
key string

Key to be returned.

escape boolean <optional>

Whether you want to espace the value or not.

Inherited From:
Source:
Returns:
Type
*

getData() → {*}

Returns class data.

Inherited From:
Source:
Returns:

Class data.

Type
*

getKeys() → {Array}

Returns keys array.

Inherited From:
Source:
Returns:

Keys array.

Type
Array

getOption() → {*}

Returns value of a key in options object.

Inherited From:
Source:
Returns:

Value of key or null.

Type
*

getOptions() → {Object}

Returns all options object.

Inherited From:
Source:
Returns:

Options object.

Type
Object

getUid() → {string}

Return unique id.

Inherited From:
Source:
Returns:

Unique id of this component.

Type
string

<private> getUrl_(method) → {string}

This method allows RemoteStore to work with customized urls for different request types. If the url in options is string then RemoteStore will use it and don't touch it. It may also be a function which will return different urls for different request types. See the following example.

    new spark.core.RemoteStore
      url: (type) ->
        if type is 'GET'
          return '/user/list'
        else if type is 'POST'
          return '/user'
Parameters:
Name Type Description
method string

Request type to customize request url.

Source:
Returns:

The request url.

Type
string

getValues() → {Array}

Returns values array.

Inherited From:
Source:
Returns:

Values array.

Type
Array

has(key) → {boolean}

Returns true if the store has the given key.

Parameters:
Name Type Description
key string

Key to be searched in store.

Inherited From:
Source:
Returns:

Whether the store has the key or not.

Type
boolean

isDestroyed() → {boolean}

Returns the object's destroy state.

Inherited From:
Source:
Returns:

Whether the object is destroyed or not.

Type
boolean

off(eventName, callback) → {boolean}

Removes an event listener which was added with @on or @once. See also goog.events.Listenable.prototype.unlisten

Parameters:
Name Type Description
eventName string

Name of the event.

callback function

Callback function for the event.

Inherited From:
Source:
Returns:

Whether any listener was removed.

Type
boolean

on(eventName, callback) → {goog.events.ListenableKey|number}

Adds an event listener. See also goog.events.Listenable::listen

Parameters:
Name Type Description
eventName string

Name of the event.

callback function

Callback function for the event.

Inherited From:
Source:
Returns:

Unique key for the listener.

Type
goog.events.ListenableKey | number

once(eventName, callback) → {goog.events.ListenableKey|number}

Adds an event listener that is removed automatically after the listener fired once. See also goog.events.Listenable.prototype.listenOnce

Parameters:
Name Type Description
eventName string

Name of the event.

callback function

Callback function for the event.

Inherited From:
Source:
Returns:

Unique key for the listener.

Type
goog.events.ListenableKey | number

remove(callback)

Removes a store on the server by making a HTTP DELETE request. Handle the response with a callback or emitted events. Depending the response EventTypes.REMOVED or EventTypes.REMOVE_FAILED events will be emitted.

Parameters:
Name Type Argument Description
callback function <optional>

Callback function to handle the request.

Source:

save(callback)

Saves the data to server or updates it on the server. If your data has options.idKey property it will make a PUT request to update the data otherwise it will make a POST request to save it to server. If server response includes an options.idKey RemoteStore will save the id and use it to update the data.

Parameters:
Name Type Argument Description
callback function <optional>

Callback function to handle the request.

Source:

set(key, value) → {boolean}

Sets a new key value pair into store. It will also make a validation before setting the new value. If you set a validation rule in options.validations for that property, when validation failed, the property won't be updated. Store::set will return no and emit a 'PropertyRejected' event otherwise it will return true and it will also emit 'ProperySet'. Both events will include key and value. If the key and value passed to set does not related with a validation rule, it will directly set to store. This makes validation optional.

Parameters:
Name Type Description
key string

Key to be returned.

value *

Value of the key.

Inherited From:
Source:
Returns:

Whether the set is completed or not.

Type
boolean

setData(data)

Sets data of this class.

Parameters:
Name Type Description
data *

Data passed to class.

Inherited From:
Source:

setOptions(options)

Sets options object of this class.

Parameters:
Name Type Description
options Object

Options object.

Inherited From:
Source:

<private> setUid_()

Sets uid.

Inherited From:
Source:

toObject() → {Object}

Returns the current data as object.

Inherited From:
Source:
Returns:

Store data.

Type
Object

unset(key) → {boolean}

Removes a key from strore.

Parameters:
Name Type Description
key string

Key to be removed.

Inherited From:
Source:
Returns:

Whether the key removed or not.

Type
boolean

validate(key, value) → {boolean}

Validates the given value for given key's validation rules.

Parameters:
Name Type Description
key string

Key to be validated.

value *

Value of the key to validate.

Inherited From:
Source:
Returns:

Whether the validation is passed or failed.

Type
boolean

validateAll()

Validates all data and throw an error if validation fails.

Inherited From:
Source:
Spark Framework by Fatih Acet
Copyright © 2014 - Fatih Acet
Documentation generated by JSDoc 3.2.2 on 2015-07-19T22:09:34+00:00 using the DocStrap template.