<commit_before>{ UIRouter, $q } = require('ui-router-core')
{ mnViewsBuilder, MnViewConfig } = require('./state_views_builder')
{ hashLocationPlugin, servicesPlugin } = require('ui-router-core/lib/vanilla')
{ UIViewMarionette } = require('./uiview')

routerInstance = null

viewConfigFactory = (node, config) ->
  new MnViewConfig(node, config)


class UIRouterMarionette extends UIRouter
  @getInstance: ->
    routerInstance or= new @

  constructor: ->
    super
    @_started = false
    @viewService._pluginapi._viewConfigFactory('backbone', viewConfigFactory)
    @plugin(servicesPlugin)
    @plugin(hashLocationPlugin)

    @stateRegistry.decorator("views", mnViewsBuilder)
    routerInstance = @

  start: (@rootRegion) ->
    throw new Error("Router was already started") if @_started

    @rootRegion.uiView = new UIViewMarionette(@, null, @rootRegion, "")
    @rootRegion.uiView.register()

    @urlMatcherFactory.$get()
    @urlService.listen()
    @urlService.sync()
    @_started = true
    return @



exports.UIViewMarionette = UIViewMarionette
exports.UIRouterMarionette = UIRouterMarionette<commit_msg>WIP patching backbone router to monitor "legacy" route events<commit_after>{ UIRouter, $q } = require('ui-router-core')
{ mnViewsBuilder, MnViewConfig } = require('./state_views_builder')
{ hashLocationPlugin, servicesPlugin } = require('ui-router-core/lib/vanilla')
{ UIViewMarionette } = require('./uiview')

routerInstance = null

viewConfigFactory = (node, config) ->
  new MnViewConfig(node, config)


class UIRouterMarionette extends UIRouter
  @getInstance: ->
    routerInstance or= new @

  constructor: ->
    super
    @_started = false
    @viewService._pluginapi._viewConfigFactory('backbone', viewConfigFactory)
    @plugin(servicesPlugin)
    @plugin(hashLocationPlugin)

    @stateRegistry.decorator("views", mnViewsBuilder)
    routerInstance = @

  start: (@rootRegion, options) ->
    throw new Error("Router was already started") if @_started

    if options?
      @handleOptions(options)

    @rootRegion.uiView = new UIViewMarionette(@, null, @rootRegion, "")
    @rootRegion.uiView.register()

    @urlMatcherFactory.$get()
    @urlService.listen()
    @urlService.sync()
    @_started = true
    return @

  handleOptions: (options) ->
    if typeof options.onMarionetteRoute is 'function'
      @patchMnRouter(options.onMarionetteRoute)

  patchMnRouter: (onRoute) ->
    oldProcessOnRoute = Marionette.AppRouter::_processOnRoute
    Marionette.AppRouter::_processOnRoute = (routeName, routeArgs) ->
      onRoute.call(@, routeName, routeArgs)
      oldProcessOnRoute.call(@, routeName, routeArgs)


exports.UIViewMarionette = UIViewMarionette
exports.Router = UIRouterMarionette
{'fraction_non_alphanumeric': 0.11853211009174312, 'fraction_numerical': 0.0, 'mean_word_length': 4.518218623481781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1843065', 'n_tokens_mistral': 849, 'n_tokens_neox': 818, 'n_words': 162}