Sha256: ed7f8122a0ad29a0fa603794f612ad18ddf4a3ae7125b5470dba52bbe6564ad5

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

namespace "SensuDashboard", (exports) ->

  class exports.StateManager extends Backbone.Router

    views: []

    constructor: (states, defaultState) ->
      @_buildStates(states)
      @_buildRoutes()
      @_defaultRoute(defaultState)
      super

    register: (view) ->
      @views.push(view)

    disposeAll: ->
      view.dispose() for view in @views

    reset: ->
      @disposeAll()
      @views = []

    count: ->
      @views.length

    pushTop: (view) ->
      @reset()
      @register(view)

    # Private

    _getState: (name) ->
      _.find @states, (state) ->
        state.name == name

    _buildStates: (states) ->
      @states = []
      @states.push(new state(name: name)) for name, state of states

    _buildRoutes: ->
      for state in @states
        @route state.route, state.name, @_enterView(state)

    _defaultRoute: (defaultState) ->
      defaultState ||= @states[0].name
      state = @_getState(defaultState)
      @route "", defaultState, @_enterView(state)

    _enterView: (state) ->
      (context) ->
        view = state.enter(context)
        state.transition(@, view)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sensu-dashboard-0.10.4 lib/sensu-dashboard/assets/javascripts/state_manager.coffee
sensu-dashboard-0.10.3 lib/sensu-dashboard/assets/javascripts/state_manager.coffee
sensu-dashboard-0.10.2 lib/sensu-dashboard/assets/javascripts/state_manager.coffee
sensu-dashboard-0.10.1 lib/sensu-dashboard/assets/javascripts/state_manager.coffee
sensu-dashboard-0.10.0 lib/sensu-dashboard/assets/javascripts/state_manager.coffee
sensu-dashboard-0.9.9 lib/sensu-dashboard/assets/javascripts/state_manager.coffee