new View(params)
Create a View
Parameters:
Name | Type | Description | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object |
Properties
|
Members
$selector
Get a Query instance of the selector passed in to the view constructor.
documentListener
Get DocumentListener singleton.
eventBus
Get EventBus singleton.
router
Get Router singleton.
Methods
addBinded(binded)
Convenience method to help bind view methods to this (eg. 'foo' -> this.foo.bind(this)). Binded methods can be accessed using this.binded.foo.
Parameters:
Name | Type | Description |
---|---|---|
binded |
Array.<string> |
addEvents(events)
Events will be passed to DocumentListener.on for DOM events and View.on for custom events. If Event.context is not set, it will default to the View instance.
Parameters:
Name | Type | Description |
---|---|---|
events |
Array.<View~Event> |
addRoute(route)
Route will be passed to Router.add. Route.listener should be passed in as a string and will be changed to a method on the View instance. (eg. 'show' -> this.show).
Parameters:
Name | Type | Description |
---|---|---|
route |
Router~Route |
(async) fetch(params) → {View~FetchResult}
Wrapper for native fetch. The response is automatically parsed as JSON. If browser does not support fetch, this falls back to xhr
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
params |
Object | All params passed in will be passed to native fetch. Properties
|
Returns:
- Type
- View~FetchResult
off(type, listener)
convenience method passed to EventBus.off.
Parameters:
Name | Type | Description |
---|---|---|
type |
string | the name of the event to stop listening to. |
listener |
function | The callback function for this event. |
on(type, listener, contextopt)
convenience method passed to EventBus.on.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type |
string | the name of the event to listen on. |
||
listener |
function | The callback function for when this event is triggered. |
||
context |
object |
<optional> |
this | The value of 'this' provided to the listener. |
render(paramsopt)
Takes the passed in data object, runs it through the template function and inserts it into the selector element. Passing params is optional and will default to the params passed to the view instance constructor.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object |
<optional> |
Properties
|
trigger(type, data)
convenience method passed to EventBus.trigger.
Parameters:
Name | Type | Description |
---|---|---|
type |
string | the name of the event to trigger. |
data |
object | Arbitrary data to pass with the event. |
Type Definitions
Event
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
type |
string | DOM event (eg. 'click') or custom event ('myevent'). |
selector |
string | If it's a DOM event, the selector to listen on. |
listener |
string | The callback function for when this event is triggered. Param is passed in as a string and turned in to a method on the View instance (eg. 'show' -> this.show). |
context |
Object | The value of 'this' provided to the listener. |
FetchResult
Type:
- object
Properties:
Name | Type | Description |
---|---|---|
data |
object | The JSON data returned from the remote call. |
error |
boolean | If the response status > 400, this is set to true. |
status |
number | The http response code |