Home Manual Reference Source Repository
public class | source

App

Provides the main entry point for the Todos app and major control functionality (the C in MVC). This control functionality is exposed over an eventbus created by mainEventbus.js. typhonjs-backbone-parse provides additional functionality particularly for Backbone.Events adding the ability to invoke asynchronous actions over the eventbus using the triggerThen method which resolves any Promises returned by event targets.

While in this simple app there is only one view of the TodoList a benefit of separating control functionality and the TodoList instance from a specific view is that it could be used across multiple views.

Please note that all Parse specific API access is isolated in this class. By isolating Parse API access to just this class if the app was rewritten to use a different backend then only this class needs to be modified to support the new backend API after selecting an alternate Backbone implementation.

Constructor Summary

Public Constructor
public

Wires up the main eventbus, invokes the private s_INITIALIZE_ROUTE function which creates AppRouter and sets up a catch all handler then invokes Backbone.history.start with the root path and finally the constructor shows the proper view based on whether there is a current logged in user.

Member Summary

Public Members
public

Creates the initial displayed view based given if a user is currently logged into the app.

Method Summary

Public Methods
public

createItem(content: string)

Creates a new Item in the todos list.

public

Returns a boolean indicating if a user is logged into the app.

public

Logs in the user and invokes showTodos on success.

public

Logs out the user and shows the login view.

public

selectFilter(filter: string)

Sets the app state with the new filter type and updates Backbone.History.

public

showTodos(username: string): *

Creates and shows a new ManageTodosView then sets a new Parse.Query for todoList for the current user and fetches the collection.

public

Potentially signs up a new user and if successful invokes showTodos.

Public Constructors

public constructor source

Wires up the main eventbus, invokes the private s_INITIALIZE_ROUTE function which creates AppRouter and sets up a catch all handler then invokes Backbone.history.start with the root path and finally the constructor shows the proper view based on whether there is a current logged in user.

Public Members

public currentView: View source

Creates the initial displayed view based given if a user is currently logged into the app.

Public Methods

public createItem(content: string) source

Creates a new Item in the todos list. Note the addition of user which becomes a Parse pointer and an Parse.ACL (access control list) which limits the item to be only accessible to the current user.

Params:

NameTypeAttributeDescription
content string

The text for the item.

public isUserCurrent(): boolean source

Returns a boolean indicating if a user is logged into the app.

Return:

boolean

public logInUser(data: object): Promise source

Logs in the user and invokes showTodos on success.

Please note that an ES6 Promise wraps the Parse API call and this promise is resolved by the TyphonJS eventbus via Promise.all before executing any handlers by the callee of triggerThen.

Params:

NameTypeAttributeDescription
data object

An object that has username & password entries.

Return:

Promise

public logOutUser(): Promise source

Logs out the user and shows the login view.

Please note that an ES6 Promise wraps the Parse API call and this promise is resolved by the TyphonJS eventbus via Promise.all before executing any handlers by the callee of triggerThen.

Return:

Promise

public selectFilter(filter: string) source

Sets the app state with the new filter type and updates Backbone.History.

Params:

NameTypeAttributeDescription
filter string

Filter type to select.

public showTodos(username: string): * source

Creates and shows a new ManageTodosView then sets a new Parse.Query for todoList for the current user and fetches the collection.

Params:

NameTypeAttributeDescription
username string

Name of current user.

Return:

*

public signUpUser(data: object): Promise source

Potentially signs up a new user and if successful invokes showTodos.

Please note that an ES6 Promise wraps the Parse API call and this promise is resolved by the TyphonJS eventbus via Promise.all before executing any handlers by the callee of triggerThen.

Params:

NameTypeAttributeDescription
data object

An object that has username & password entries.

Return:

Promise