Home Reference Source
import {DataSource} from 'arva-js/data/DataSource.js'
public class | source

DataSource

@author: Tom Clement (tjclement)

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public get

Indicate that the DataSource can be inherited when instantiating a list of models.

Method Summary

Public Methods
public

authAnonymously(onComplete: Function, options: Object): void

Authenticates all instances of this DataSource as an anonymous user.

public

authWithCustomToken(authToken: String, onComplete: Function, options: Object): void

Authenticates all instances of this DataSource with a custom auth token or secret.

public

authWithOAuthToken(provider: String, credentials: String | Object, onComplete: Function, options: Object): void

Authenticates all instances of this DataSource with the given OAuth provider and credentials.

public

authWithPassword(credentials: String | Object, onComplete: Function, options: Object): void

Authenticates all instances of this DataSource with the given email/password credentials.

public

child(childName: String, options: Object): DataSource

Returns a dataSource reference to the given child branch of the current dataSource.

public

Fetches the current user's authentication state. If the user is authenticated, returns an object containing at least the fields uid, provider, auth, and expires. If the user is not authenticated, returns null.

public

key(): String

Returns the name of the current branch in the path on the dataSource.

public

Returns a new dataSource reference that will limit the subscription to only the first given amount items.

public

Returns a new dataSource reference that will limit the subscription to only the last given amount items.

public

off(event: String, handler: Function)

Unsubscribe to a previously subscribed event.

public

on(event: String, handler: Function, context: Object)

Subscribe to an event emitted by the DataSource.

public

once(event: String, handler: Function, context: Object)

Subscribe to an event emitted by the DataSource once, and then immediately unsubscribe.

public

Orders the DataSource's childs by the value in child[key].

public

Orders the DataSource's childs by their key names, ignoring their priority.

public

Orders the DataSource's childs by their values, ignoring their priority.

public

Returns the full URL to the path on the dataSource.

public

push(newData: Object): void

Writes newData to the path this dataSource was constructed with, appended by a random UID generated by the dataSource.

public

remove(): void

Removes the object and all underlying children that this dataSource points to.

public

Removes the callback set to trigger when dataSource adds a data element.

public

Removes the callback set to trigger when dataSource changes a data element.

public

Removes the callback set to trigger when dataSource moves a data element.

public

Removes the callback set to trigger when dataSource removes a data element.

public

Removes the callback set to trigger when dataSource updates the data.

public

set(newData: Object): Promise

Writes newData to the path this dataSource was constructed with.

public

setChildAddedCallback(callback: Function): void

Set the callback triggered when dataSource adds a data element.

public

Set the callback triggered when dataSource changes a data element.

public

setChildMovedCallback(callback: Function): void

Set the callback triggered when dataSource moves a data element.

public

Set the callback triggered when dataSource removes a data element.

public

setPriority(newPriority: String | Number): void

Sets the priority (ordering) of an object on a given dataSource.

public

Sets the callback triggered when dataSource updates the data.

public

setWithPriority(newData: Object, priority: String | Number): Promise

Writes newData with given priority (ordering) to the path this dataSource was constructed with.

public

Resolves when the DataSource is synchronized to the server

public

Returns the full path to this dataSource's source on the remote storage provider.

public

unauth(): void

Logs out from the datasource, allowing to re-authenticate at a later time.

Public Constructors

public constructor(path: String): DataSource source

Params:

NameTypeAttributeDescription
path String

Full path to resource in remote data storage.

Return:

DataSource

DataSource instance.

Public Members

public get inheritable: Boolean: boolean source

Indicate that the DataSource can be inherited when instantiating a list of models. By default we indicate false, which should trigger data model instantiation to create unique DataSource references to each model either in array or directly.

If set to false, model updates trigger creation of a new DataSource instance. (default)

Return:

Boolean

Whether the DataSource is inheritable.

Public Methods

public authAnonymously(onComplete: Function, options: Object): void source

Authenticates all instances of this DataSource as an anonymous user.

Params:

NameTypeAttributeDescription
onComplete Function

Callback, executed when login is completed either successfully or erroneously. On error, first argument is error message. On success, the first argument is null, and the second argument is an object containing the fields uid, provider, auth, and expires.

options Object

Optional, additional client arguments, such as configuring session persistence.

Return:

void

public authWithCustomToken(authToken: String, onComplete: Function, options: Object): void source

Authenticates all instances of this DataSource with a custom auth token or secret.

Params:

NameTypeAttributeDescription
authToken String

Authentication token or secret.

onComplete Function

Callback, executed when login is completed either successfully or erroneously. On error, first argument is error message. On success, the first argument is null, and the second argument is an object containing the fields uid, provider, auth, and expires.

options Object

Optional, additional client arguments, such as configuring session persistence.

Return:

void

public authWithOAuthToken(provider: String, credentials: String | Object, onComplete: Function, options: Object): void source

Authenticates all instances of this DataSource with the given OAuth provider and credentials.

Params:

NameTypeAttributeDescription
provider String

google, facebook, github, or twitter

credentials String | Object

Access token string, or object with key/value pairs with e.g. OAuth 1.1 credentials.

onComplete Function

Callback, executed when login is completed either successfully or erroneously. On error, first argument is error message. On success, the first argument is null, and the second argument is an object containing the fields uid, provider, auth, and expires.

options Object

Optional, additional client arguments, such as configuring session persistence.

Return:

void

public authWithPassword(credentials: String | Object, onComplete: Function, options: Object): void source

Authenticates all instances of this DataSource with the given email/password credentials.

Params:

NameTypeAttributeDescription
credentials String | Object

Object with key/value pairs {email: "value", password:"value"}.

onComplete Function

Callback, executed when login is completed either successfully or erroneously. On error, first argument is error message. On success, the first argument is null, and the second argument is an object containing the fields uid, provider, auth, and expires.

options Object

Optional, additional client arguments, such as configuring session persistence.

Return:

void

public child(childName: String, options: Object): DataSource source

Returns a dataSource reference to the given child branch of the current dataSource.

Params:

NameTypeAttributeDescription
childName String

Child branch name.

options Object

Optional: additional options to pass to new DataSource instance.

Return:

DataSource

New dataSource instance pointing to the given child branch.

public getAuth(): Object | null source

Fetches the current user's authentication state. If the user is authenticated, returns an object containing at least the fields uid, provider, auth, and expires. If the user is not authenticated, returns null.

Return:

Object | null

User auth object.

public key(): String source

Returns the name of the current branch in the path on the dataSource.

Return:

String

Current branch name.

public limitToFirst(amount: Number): DataSource source

Returns a new dataSource reference that will limit the subscription to only the first given amount items.

Params:

NameTypeAttributeDescription
amount Number

Amount of items to limit the dataSource to.

Return:

DataSource

New dataSource instance.

public limitToLast(amount: Number): DataSource source

Returns a new dataSource reference that will limit the subscription to only the last given amount items.

Params:

NameTypeAttributeDescription
amount Number

Amount of items to limit the dataSource to.

Return:

DataSource

New dataSource instance.

public off(event: String, handler: Function) source

Unsubscribe to a previously subscribed event. If no handler or context is given, all handlers for the given event are removed. If no parameters are given at all, all event types will have their handlers removed.

Params:

NameTypeAttributeDescription
event String

Event type to unsubscribe from. Allowed values are: 'value', 'child_changed', 'child_added', 'child_removed', 'child_moved'.

handler Function

Optional: Function that was used in previous subscription.

public on(event: String, handler: Function, context: Object) source

Subscribe to an event emitted by the DataSource.

Params:

NameTypeAttributeDescription
event String

Event type to subscribe to. Allowed values are: 'value', 'child_changed', 'child_added', 'child_removed', 'child_moved'.

handler Function

Function to call when the subscribed event is emitted.

context Object

Context to set 'this' to when calling the handler function.

public once(event: String, handler: Function, context: Object) source

Subscribe to an event emitted by the DataSource once, and then immediately unsubscribe.

Params:

NameTypeAttributeDescription
event String

Event type to subscribe to. Allowed values are: 'value', 'child_changed', 'child_added', 'child_removed', 'child_moved'.

handler Function

Function to call when the subscribed event is emitted.

context Object

Context to set 'this' to when calling the handler function.

public orderByChild(childKey: String): DataSource source

Orders the DataSource's childs by the value in child[key].

Params:

NameTypeAttributeDescription
childKey String

Key of the field to order by.

Return:

DataSource

New dataSource instance.

public orderByKey(): DataSource source

Orders the DataSource's childs by their key names, ignoring their priority.

Return:

DataSource

New dataSource instance.

public orderByValue(): DataSource source

Orders the DataSource's childs by their values, ignoring their priority.

Return:

DataSource

New dataSource instance.

public path(): String source

Returns the full URL to the path on the dataSource. Functionally identical to toString().

Return:

String

Full resource path.

public push(newData: Object): void source

Writes newData to the path this dataSource was constructed with, appended by a random UID generated by the dataSource.

Params:

NameTypeAttributeDescription
newData Object

New data to append to dataSource.

Return:

void

public remove(): void source

Removes the object and all underlying children that this dataSource points to.

Return:

void

public removeChildAddedCallback(): void source

Removes the callback set to trigger when dataSource adds a data element.

Return:

void

public removeChildChangedCallback(): void source

Removes the callback set to trigger when dataSource changes a data element.

Return:

void

public removeChildMovedCallback(): void source

Removes the callback set to trigger when dataSource moves a data element.

Return:

void

public removeChildRemovedCallback(): void source

Removes the callback set to trigger when dataSource removes a data element.

Return:

void

public removeValueChangedCallback(): void source

Removes the callback set to trigger when dataSource updates the data.

Return:

void

public set(newData: Object): Promise source

Writes newData to the path this dataSource was constructed with.

Params:

NameTypeAttributeDescription
newData Object

Data to write to dataSource.

Return:

Promise

Resolves when write to server is complete.

public setChildAddedCallback(callback: Function): void source

Set the callback triggered when dataSource adds a data element.

Params:

NameTypeAttributeDescription
callback Function

Callback function to call when a new data child is added.

Return:

void

public setChildChangedCallback(callback: Function): void source

Set the callback triggered when dataSource changes a data element.

Params:

NameTypeAttributeDescription
callback Function

Callback function to call when a child is changed.

Return:

void

public setChildMovedCallback(callback: Function): void source

Set the callback triggered when dataSource moves a data element.

Params:

NameTypeAttributeDescription
callback Function

Callback function to call when a child is moved.

Return:

void

public setChildRemovedCallback(callback: Function): void source

Set the callback triggered when dataSource removes a data element.

Params:

NameTypeAttributeDescription
callback Function

Callback function to call when a child is removed.

Return:

void

public setPriority(newPriority: String | Number): void source

Sets the priority (ordering) of an object on a given dataSource.

Params:

NameTypeAttributeDescription
newPriority String | Number

New priority value to order data by.

Return:

void

public setValueChangedCallback(callback: Function): void source

Sets the callback triggered when dataSource updates the data.

Params:

NameTypeAttributeDescription
callback Function

Callback function to call when the subscribed data value changes.

Return:

void

public setWithPriority(newData: Object, priority: String | Number): Promise source

Writes newData with given priority (ordering) to the path this dataSource was constructed with.

Params:

NameTypeAttributeDescription
newData Object

New data to set.

priority String | Number

Priority value by which the data should be ordered.

Return:

Promise

Resolves when write to server is complete.

public synced(): Promise source

Resolves when the DataSource is synchronized to the server

Return:

Promise

Resolves when the DataSource is synchronized

public toString(): String source

Returns the full path to this dataSource's source on the remote storage provider.

Return:

String

Full resource path.

public unauth(): void source

Logs out from the datasource, allowing to re-authenticate at a later time.

Return:

void