Some utils to make easy work with Backbone
(Version 3.0.0)
jQuery (http://jquery.com/)
Underscore (http://underscorejs.org/)
Backbone (http://backbonejs.org/)
Some additions to backbone for simplifies application.
If you use Logger - logger name will be 'backboneExtension'.
Logger should be set to window.Logger
Available through npm
npm i @artfable/backbone-extension
Configuration for common part of the title, for all views. Set to Backbone._commonTitleConfig
Additional methods to the Backbone.View
and some changes on it. View
is a some part of a page.
Address of template with what view will be associated.
Underscore template from file that was define in templateUrl
.
Deprecated, use origin Backbone events.
Structure of events:
- selector - string or function. Selector of a DOM element. If function - must return string,
this
will be the View. - event - string. JQuery event
- call - string. Name of callback function, this function must be declared in the view. The entrees param is
event
. - params - Object, optional. Parameters that will be given to callback function as
event.data
Deprecated, use origin Backbone events.
Apply events to DOM elements. Should be called in resolve
, after view will be rendered.
Set it if you need to change title for page associated with this view. No action if it's not set. To reset for only common part - set ''.
Set page title and add common part to it, if it's turned on (see _commonTitleConfig
).
Should be used instead of initialize
.
Should be used instead of render
. Arguments
- some parameters that was sent from router
.
Include all View
s from page, and a Layout
to locate them. Backbone.Page
.
Set it if you need to change title for page associated with this view. If it's not set, apply only common part to title (see \_commonTitleConfig
).
List of metadata of View
s that Page
content. Each metadata consist of:
- region -
string
. Selector of block whereView
must be rendered. - view -
Backbone.View
Layout for Page
.
Some options to render layout, can be used in layout template.
Set page title and add common part to it, if it's turned on (see _commonTitleConfig
).
Some actions, that will be done, after the page will be initialized.
Layout for View
s on Page
.
Address of template with what layout will be associated.
Underscore template from file that was define in templateUrl
.
See in Backbone. Backbone.View.el
and Backbone.View.$el
.
Some actions, that will be done, after the layout will be initialized.
Some actions, that will be done, after the layout will be rendered.
Set View
to chosen region.
- region -
string
. Selector of block whereView
must be rendered. - view -
Backbone.View
The builder for construct Backbone.Router
. Log navigation to debug level. Save information about navigation. Backbone.routerBuilder
stateHolder - Backbone.Model
. Model that will be kept information about navigation. In property page
will be name of function that was called.
Add route.
- path - string. Route.
- actionName - name of the route.
- action - function or
View
orPage
that will be called on the path.
Add route that will be at the start page. Same as addRoute
, but path
is already set with all possible paths.
- actionName - name of the route.
- action - function or
View
orPage
that must be rendered on start page.
Some extra options for add to Backbone.Router
.
Should be called at the end. Create and return Backbone.Router
.
Result of RouterBuilder
.
Now, by default set name
(name of the route) into stateHolder
, into property page
.
Also log name
in console with debug
level.
Add route.
- route - string. Route.
- name - name of the route.
- view -
View
orPage
that will be called on the route.
Add route that will be at the start page. Same as routeByView
, but route
is already set with all possible paths.
- name - name of the route.
- view -
View
orPage
that must be rendered on start page.
Note! If you set it after call Backbone.history.start
, then it won't open page first time. Or you need to restart.