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 is the central entry point for a Batman application. @run takes these steps to initialize a Batman application:

    1. Instantiate a Dispatcher, an internal object for mananging action dispatch to controllers.
    2. Instantiate a Navigator, an internal object for managing the URL via pushState or hashbangs.
    3. Instantiate the layout view according to the layout property on the App.
    4. Wait for the layout view to fire it's ready event.
    5. Start the first action dispatch by telling the Navigator to begin monitoring the URL.

    Note: @run emits the run class event on the App, but not necessarily as soon as @run is called. Because the layout View renders asynchronously and may need to fetch other components, the run event can and often does fire long after @run is called. If you need to execute code as soon as the App has started running, add a listener to the run event on the App class. If you need to execute code as soon as the layout has rendered, you can use the ready event on the App class.

    @run can be called before or on the load DOMEvent of the window. @run will return the App if the commencement was successful and complete, or false if the App must wait for the layout to render or if the App has already run.

    starting an application with DOMEvents

    window.addEventListener 'load', ->

    starting an application with jQuery

    $ ->
  • @stop() : App

    @stop stops the App 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 level NamedRouteQuery which allows for binding to routes on objects. See data-route bindings for more information.

  • @controllers

    @controllers is a class level property containing the singleton Batman.Controller instances for each subclass in the application. This controllers directory puts these instances at the lowercase name of the controller. For example, the TodosController would be found at controllers.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 any data-yield's, when is called. Use MyApp.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.