DataSource
Direct Subclass:
@author: Tom Clement (tjclement)
Constructor Summary
Public Constructor | ||
public |
constructor(path: String): DataSource |
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 |
Returns the name of the current branch in the path on the dataSource. |
|
public |
limitToFirst(amount: Number): DataSource Returns a new dataSource reference that will limit the subscription to only the first given amount items. |
|
public |
limitToLast(amount: Number): DataSource Returns a new dataSource reference that will limit the subscription to only the last given amount items. |
|
public |
Unsubscribe to a previously subscribed event. |
|
public |
Subscribe to an event emitted by the DataSource. |
|
public |
Subscribe to an event emitted by the DataSource once, and then immediately unsubscribe. |
|
public |
orderByChild(childKey: String): DataSource 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 |
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 |
removeChildAddedCallback(): void Removes the callback set to trigger when dataSource adds a data element. |
|
public |
removeChildChangedCallback(): void Removes the callback set to trigger when dataSource changes a data element. |
|
public |
removeChildMovedCallback(): void Removes the callback set to trigger when dataSource moves a data element. |
|
public |
removeChildRemovedCallback(): void Removes the callback set to trigger when dataSource removes a data element. |
|
public |
removeValueChangedCallback(): void Removes the callback set to trigger when dataSource updates the data. |
|
public |
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 |
setChildChangedCallback(callback: Function): void 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 |
setChildRemovedCallback(callback: Function): void 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 |
setValueChangedCallback(callback: Function): void 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:
Name | Type | Attribute | Description |
path | String | Full path to resource in remote data storage. |
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)
Public Methods
public authAnonymously(onComplete: Function, options: Object): void source
Authenticates all instances of this DataSource as an anonymous user.
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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.
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.
public limitToFirst(amount: Number): DataSource source
Returns a new dataSource reference that will limit the subscription to only the first given amount items.
Params:
Name | Type | Attribute | Description |
amount | Number | Amount of items to limit the dataSource to. |
public limitToLast(amount: Number): DataSource source
Returns a new dataSource reference that will limit the subscription to only the last given amount items.
Params:
Name | Type | Attribute | Description |
amount | Number | Amount of items to limit the dataSource to. |
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.
public on(event: String, handler: Function, context: Object) source
Subscribe to an event emitted by the DataSource.
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
childKey | String | Key of the field to order by. |
public orderByKey(): DataSource source
Orders the DataSource's childs by their key names, ignoring their priority.
public orderByValue(): DataSource source
Orders the DataSource's childs by their values, ignoring their priority.
public path(): String source
Returns the full URL to the path on the dataSource. Functionally identical to toString().
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
newData | Object | Data to write to dataSource. |
public setChildAddedCallback(callback: Function): void source
Set the callback triggered when dataSource adds a data element.
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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.
Return:
void |
public setValueChangedCallback(callback: Function): void source
Sets the callback triggered when dataSource updates the data.
Params:
Name | Type | Attribute | Description |
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.
public toString(): String source
Returns the full path to this dataSource's source on the remote storage provider.
public unauth(): void source
Logs out from the datasource, allowing to re-authenticate at a later time.
Return:
void |