Reference Source
public class | source

HomeModel

Extends:

* → HomeModel

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
Private Members
private
private
private

_data: {"data": *}

Method Summary

Public Methods
public

get(): Object

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

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

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

Unsets a bookmark for a specific ID

public

update(newData: Object)

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

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 get(): Object source

Get method for presenters to get data.

Return:

Object

data stored in the model

public getBookmarkedData(data: List, toggle: Boolean): List source

Gets the bookmarked or unbookmarked data from based on the toggle value.

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
id Number

A bike notification ID

Return:

Boolean

true: if ID is bookmarked by user; false: otherwise

public moveBookmarkedDataToFront() source

Moves the bookmarked data to the front of the list.

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
id Number

A bike nofication ID to unbookmark

public update(newData: Object) source

Update method for presenters to update the model's data.

Params:

NameTypeAttributeDescription
newData Object

New data to add

Private Methods

private _defaultCallback(message: *) source

Default callback

Params:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
newData Object

Data to be written to the database

callback Function

A function to call on the success or failure of the call

Return:

*

private _insertDataOnRead(databaseData: Object) source

Insert data into the data object when data has changed from the database

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
data Object

Data to remove

private forceNotifyAll() source

private testUpdateInjection(newData: *) source

Params:

NameTypeAttributeDescription
newData *