<commit_before>'use strict'

_ = require 'underscore'
Backbone = require 'backbone'
mediator = require 'chaplin/mediator'
EventBroker = require 'chaplin/lib/event_broker'
History = require 'chaplin/lib/history'
Route = require 'chaplin/lib/route'
utils = require 'chaplin/lib/utils'

# The router which is a replacement for Backbone.Router.
# Like the standard router, it creates a Backbone.History
# instance and registers routes on it.
module.exports = class Router # This class does not extend Backbone.Router.
  # Borrow the static extend method from Backbone.
  @extend = Backbone.Model.extend

  # Mixin an EventBroker.
  _.extend @prototype, EventBroker

  constructor: (@options = {}) ->
    # Enable pushState by default for HTTP(s).
    # Disable it for file:// schema.
    isWebFile = window.location.protocol isnt 'file:'
    _.defaults @options,
      pushState: isWebFile
      root: '/'

    # Cached regex for stripping a leading subdir and hash/slash.
    @removeRoot = new RegExp('^' + utils.escapeRegExp(@options.root) + '(#)?')

    mediator.setHandler 'router:route', @route, this
    mediator.setHandler 'router:reverse', @reverse, this
    mediator.setHandler 'router:changeURL', @changeURL, this

    @createHistory()
<commit_msg>Add early errors for old !router events.<commit_after>'use strict'

_ = require 'underscore'
Backbone = require 'backbone'
mediator = require 'chaplin/mediator'
EventBroker = require 'chaplin/lib/event_broker'
History = require 'chaplin/lib/history'
Route = require 'chaplin/lib/route'
utils = require 'chaplin/lib/utils'

# The router which is a replacement for Backbone.Router.
# Like the standard router, it creates a Backbone.History
# instance and registers routes on it.
module.exports = class Router # This class does not extend Backbone.Router.
  # Borrow the static extend method from Backbone.
  @extend = Backbone.Model.extend

  # Mixin an EventBroker.
  _.extend @prototype, EventBroker

  constructor: (@options = {}) ->
    # Enable pushState by default for HTTP(s).
    # Disable it for file:// schema.
    isWebFile = window.location.protocol isnt 'file:'
    _.defaults @options,
      pushState: isWebFile
      root: '/'

    # Cached regex for stripping a leading subdir and hash/slash.
    @removeRoot = new RegExp('^' + utils.escapeRegExp(@options.root) + '(#)?')

    @subscribeEvent '!router:route', @oldEventError
    @subscribeEvent '!router:routeByName', @oldEventError
    @subscribeEvent '!router:changeURL', @oldURLEventError

    mediator.setHandler 'router:route', @route, this
    mediator.setHandler 'router:reverse', @reverse, this
    mediator.setHandler 'router:changeURL', @changeURL, this

    @createHistory()

  oldEventError: ->
    throw new Error '!router:route and !router:routeByName events were removed.
  Use `Chaplin.helpers.redirectTo`'

  oldURLEventError: ->
    throw new Error '!router:changeURL event was removed.
  Use mediator.execute("router:changeURL")'

{'fraction_non_alphanumeric': 0.11017520215633424, 'fraction_numerical': 0.0, 'mean_word_length': 4.127806563039724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6318794', 'n_tokens_mistral': 889, 'n_tokens_neox': 885, 'n_words': 269}