HomeModel
Extends:
Class for the home/notification model to be used by the Home Presenter
Constructor Summary
Public Constructor | ||
public |
Creates an instance of HomeModel. |
Member Summary
Public Members | ||
public |
listener: * |
Private Members | ||
private |
_activeBookmarks: *[] |
|
private |
_callback: * |
|
private |
_data: {"data": *} |
Method Summary
Public Methods | ||
public |
Get method for presenters to get data. |
|
public |
getBookmarkedData(data: List, toggle: Boolean): List Gets the bookmarked or unbookmarked data from based on the toggle value. |
|
public |
isBookmarked(id: Number): Boolean Returns the bookmarked state for a bike ID |
|
public |
Moves the bookmarked data to the front of the list. |
|
public |
Recalculates the 'timeago' property of the object, based on the milliseconds. |
|
public |
setBookmark(id: Number) Sets a bookmark for a specific ID |
|
public |
setCallback(callback: Function) Set the model's callback to a new callback. This callback can be used anywhere and is usually passed in from a presenter. |
|
public |
Toggle the database listener off and then on again to get the data again. |
|
public |
unsetBookmark(id: Number) Unsets a bookmark for a specific ID |
|
public |
Update method for presenters to update the model's data. |
Private Methods | ||
private |
_defaultCallback(message: *) Default callback |
|
private |
_editExistingInDatabase(newData: Object, callback: Function): * Overwrite existing data in database and call the function callback depending on if it was successful or not. |
|
private |
_insertDataOnRead(databaseData: Object) Insert data into the data object when data has changed from the database |
|
private |
Register an 'on' read from the database, supplying the callback when the database has changed. |
|
private |
_removeFromData(data: Object) Remove data from the home model's data. |
|
private |
|
|
private |
testUpdateInjection(newData: *) |
Public Constructors
public constructor() source
Creates an instance of HomeModel. Initializes , creates an observerlist, and registers an on read from the database.
Public Members
public listener: * source
Private Members
private _activeBookmarks: *[] source
private _callback: * source
private _data: {"data": *} source
Public Methods
public getBookmarkedData(data: List, toggle: Boolean): List source
Gets the bookmarked or unbookmarked data from based on the toggle value.
Params:
Name | Type | Attribute | Description |
data | List | A list of objects with property id |
|
toggle | Boolean | true: Look for bookmarked data; false: Look for unbookmarked data |
Return:
List | A list of bookmarked or unbookmarked data depending on the toggle value |
public isBookmarked(id: Number): Boolean source
Returns the bookmarked state for a bike ID
Params:
Name | Type | Attribute | Description |
id | Number | A bike notification ID |
public recalculateTimeAgo() source
Recalculates the 'timeago' property of the object, based on the milliseconds.
public setBookmark(id: Number) source
Sets a bookmark for a specific ID
Params:
Name | Type | Attribute | Description |
id | Number | A bike notification ID to bookmark |
public setCallback(callback: Function) source
Set the model's callback to a new callback. This callback can be used anywhere and is usually passed in from a presenter.
Params:
Name | Type | Attribute | Description |
callback | Function | A callback to run when certain code is executed |
public toggleListeners() source
Toggle the database listener off and then on again to get the data again. TODO : Better method to do this?
public unsetBookmark(id: Number) source
Unsets a bookmark for a specific ID
Params:
Name | Type | Attribute | Description |
id | Number | A bike nofication ID to unbookmark |
public update(newData: Object) source
Update method for presenters to update the model's data.
Params:
Name | Type | Attribute | Description |
newData | Object | New data to add |
Private Methods
private _defaultCallback(message: *) source
Default callback
Params:
Name | Type | Attribute | Description |
message | * |
private _editExistingInDatabase(newData: Object, callback: Function): * source
Overwrite existing data in database and call the function callback depending on if it was successful or not.
Return:
* |
private _insertDataOnRead(databaseData: Object) source
Insert data into the data object when data has changed from the database
Params:
Name | Type | Attribute | Description |
databaseData | Object | Each data item is an object within the overall object |
private _registerDBReadListener() source
Register an 'on' read from the database, supplying the callback when the database has changed.
private _removeFromData(data: Object) source
Remove data from the home model's data.
Params:
Name | Type | Attribute | Description |
data | Object | Data to remove |
private forceNotifyAll() source
private testUpdateInjection(newData: *) source
Params:
Name | Type | Attribute | Description |
newData | * |