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 |
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 |
|
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 |
|
public |
Creates and shows a new ManageTodosView then sets a new |
|
public |
signUpUser(data: object): Promise Potentially signs up a new user and if successful invokes |
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 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:
Name | Type | Attribute | Description |
content | string | The text for the item. |
public isUserCurrent(): boolean source
Returns a boolean indicating if a user is logged into the app.
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:
Name | Type | Attribute | Description |
data | object | An object that has username & password entries. |
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
.
public selectFilter(filter: string) source
Sets the app state with the new filter type and updates Backbone.History
.
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
data | object | An object that has username & password entries. |