Batman.App
Batman.App
is the central object in any Batman application. It manages the routing table and the current URL parameters, as well as the initial start of the application. It should also be used as a namespace for models and views so that other objects can find them. Batman assumes that there will only ever be one Batman.App
in use at once.
-
Batman.currentApp
A Batman-wide reference to the currently running
Batman.App
. -
@run() : App
App.run
is the central entry point for a Batman application.@run
takes these steps to initialize a Batman application:- Instantiate a
Dispatcher
, an internal object for mananging action dispatch to controllers. - Instantiate a
Navigator
, an internal object for managing the URL via pushState or hashbangs. - Instantiate the
layout
view according to thelayout
property on theApp
. - Wait for the layout view to fire it's
ready
event. - Start the first action dispatch by telling the
Navigator
to begin monitoring the URL.
Note:
@run
emits therun
class event on theApp
, but not necessarily as soon as@run
is called. Because thelayout
View renders asynchronously and may need to fetch other components, therun
event can and often does fire long after@run
is called. If you need to execute code as soon as theApp
has started running, add a listener to therun
event on theApp
class. If you need to execute code as soon as the layout has rendered, you can use theready
event on theApp
class.@run
can be called before or on theload
DOMEvent of the window.@run
will return the App if the commencement was successful and complete, orfalse
if the App must wait for thelayout
to render or if theApp
has already run.starting an application with DOMEvents
window.addEventListener 'load', -> MyApp.run()
starting an application with jQuery
$ -> MyApp.run()
- Instantiate a
-
@stop() : App
@stop
stops theApp
it's called upon. The URL will stop being monitored and no more actions will be dispatched. In usual Batman development you shouldn't have to call this. -
@routes
@routes
is a class level property referencing the root levelNamedRouteQuery
which allows for binding to routes on objects. Seedata-route
bindings for more information. -
@controllers
@controllers
is a class level property containing the singletonBatman.Controller
instances for each subclass in the application. Thiscontrollers
directory puts these instances at the lowercase name of the controller. For example, theTodosController
would be found atcontrollers.todos
.@controllers
ideally should never be bound to, but it is very useful for debugging in the console and other such workarounds.test "App.controllers references a directory of controller instances", -> class Alfred extends Batman.App class Alfred.TodosController extends Batman.Controller controller = Alfred.get('controllers.todos') equal Batman._functionName(controller.constructor), "TodosController"
-
@layout
@layout
is the base view of the entire view hierarchy. By default, it will parse any data-* attributes in the entire document, excluding anydata-yield
's, whenApp.run()
is called. UseMyApp.layout = null
to disable the creation of this default view. -
@currentParams
@currentParams
contains the URL parameters for the current request, including the path relative to the app's base path (Batman.config.pathToApp
). Some interesting parts to look at:@currentParams.controller
,@currentParams.action
. -
@paramsManager
-
@paramsPusher
-
'run' class event
The
run
class event is fired once the app has run. This indeterminately but often happens before the app's layout has finished rendering. -
'ready' class event
The
ready
class event is fired once the app's layout is rendered.