<commit_before>class KodingRouter extends KDRouter

  @registerStaticEmitter()

  nicenames =
    StartTab  : 'Develop'

  getSectionName =(model)->
    sectionName = nicenames[model.bongo_.constructorName]
    if sectionName? then " - #{sectionName}" else ''

  constructor:(@defaultRoute)->
    @breadcrumb = []
    @defaultRoute or= location.pathname + location.search
    @openRoutes     = {}
    @openRoutesById = {}
    KD.singleton('display').on 'DisplayIsDestroyed', @bound 'cleanupRoute'

    KD.getSingleton('mainController').once 'AccountChanged', =>
      @utils.defer => @emit 'ready'

    super()

    KodingRouter.emit 'RouterReady', this

    @addRoutes getRoutes.call this

    @on 'AlreadyHere', -> log "You're already here!"

  listen:->
    super
    unless @userRoute
      {entryPoint} = KD.config
      @handleRoute @defaultRoute,{
        shouldPushState: yes
        replaceState: yes
        entryPoint
      }

  notFound =(route)->
    # defer this so that notFound can be called before the constructor.
    @utils.defer => @addRoute route, ->
      console.warn "Contract warning: shared route #{route} is not implemented."

  handleRoute:(route, options={})->
    @breadcrumb.push route

    entryPoint = options.entryPoint or KD.config.entryPoint
    frags      = route.split("?")[0].split "/"
    name       = if frags[1] is entryPoint?.slug then frags[2] else frags[1]

    appManager = KD.getSingleton 'appManager'
    if appManager.isAppInternal name
      return KodingAppsController.loadInternalApp name, (err)=>
        return warn err  if err
        KD.utils.defer => @handleRoute route, options

    if entryPoint?.slug and entryPoint.type is "group"
      entrySlug = "/" + entryPoint.slug
      # if incoming route is prefixed with groupname or entrySlug is the route
      # also we dont want koding as group name
      if not ///^#{entrySlug}///.test(route) and entrySlug isnt '/koding'
        route =  entrySlug + route

    super route, options

  handleRoot =->
    # don't load the root content when we're just consuming a hash fragment
    unless location.hash.length
      KD.singleton('display').hideAllDisplays()
      {entryPoint} = KD.config
      if KD.isLoggedIn()
        @handleRoute @userRoute or @getDefaultRoute(), {replaceState: yes, entryPoint}
      else
        @handleRoute @getDefaultRoute(), {entryPoint}
        # if not entryPoint or entryPoint?.slug is 'koding'
        #   KD.introView?.show()

  cleanupRoute:(contentDisplay)->
    delete @openRoutes[@openRoutesById[contentDisplay.id]]

  openSection:(app, group, query)->

    @ready =>
      {appManager, groupsController} = KD.singletons
      groupsController.ready =>
        @setPageTitle nicenames[app] ? app
        handleQuery = appManager.tell.bind appManager, app, "handleQuery", query

        appManager.once "AppCreated", handleQuery  unless appWasOpen = appManager.get app
        appManager.open app

        handleQuery()  if appWasOpen

  handleNotFound:(route)->

    status_404 = =>
      KDRouter::handleNotFound.call this, route

    status_301 = (redirectTarget)=>
      @handleRoute "/#{redirectTarget}", replaceState: yes

    KD.remote.api.JUrlAlias.resolve route, (err, target)->
      if err or not target? then status_404()
      else status_301 target

  getDefaultRoute:-> if KD.isLoggedIn() then '/Activity' else '/'
<commit_msg>FasterKoding: removed ready notion from router no more necessary<commit_after>class KodingRouter extends KDRouter

  @registerStaticEmitter()

  nicenames =
    StartTab  : 'Develop'

  getSectionName =(model)->
    sectionName = nicenames[model.bongo_.constructorName]
    if sectionName? then " - #{sectionName}" else ''

  constructor:(@defaultRoute)->
    @breadcrumb = []
    @defaultRoute or= location.pathname + location.search
    @openRoutes     = {}
    @openRoutesById = {}
    KD.singleton('display').on 'DisplayIsDestroyed', @bound 'cleanupRoute'

    super()

    KodingRouter.emit 'RouterReady', this

    @addRoutes getRoutes.call this

    @on 'AlreadyHere', -> log "You're already here!"

  listen:->
    super
    unless @userRoute
      {entryPoint} = KD.config
      @handleRoute @defaultRoute,{
        shouldPushState: yes
        replaceState: yes
        entryPoint
      }

  notFound =(route)->
    # defer this so that notFound can be called before the constructor.
    @utils.defer => @addRoute route, ->
      console.warn "Contract warning: shared route #{route} is not implemented."

  handleRoute:(route, options={})->
    @breadcrumb.push route

    entryPoint = options.entryPoint or KD.config.entryPoint
    frags      = route.split("?")[0].split "/"
    name       = if frags[1] is entryPoint?.slug then frags[2] else frags[1]

    appManager = KD.getSingleton 'appManager'
    if appManager.isAppInternal name
      return KodingAppsController.loadInternalApp name, (err)=>
        return warn err  if err
        KD.utils.defer => @handleRoute route, options

    if entryPoint?.slug and entryPoint.type is "group"
      entrySlug = "/" + entryPoint.slug
      # if incoming route is prefixed with groupname or entrySlug is the route
      # also we dont want koding as group name
      if not ///^#{entrySlug}///.test(route) and entrySlug isnt '/koding'
        route =  entrySlug + route

    super route, options

  handleRoot =->
    # don't load the root content when we're just consuming a hash fragment
    unless location.hash.length
      KD.singleton('display').hideAllDisplays()
      {entryPoint} = KD.config
      if KD.isLoggedIn()
        @handleRoute @userRoute or @getDefaultRoute(), {replaceState: yes, entryPoint}
      else
        @handleRoute @getDefaultRoute(), {entryPoint}
        # if not entryPoint or entryPoint?.slug is 'koding'
        #   KD.introView?.show()

  cleanupRoute:(contentDisplay)->
    delete @openRoutes[@openRoutesById[contentDisplay.id]]

  openSection:(app, group, query)->

    {appManager} = KD.singletons
    @setPageTitle nicenames[app] ? app
    handleQuery = appManager.tell.bind appManager, app, "handleQuery", query

    appManager.once "AppCreated", handleQuery  unless appWasOpen = appManager.get app
    appManager.open app

    handleQuery()  if appWasOpen

  handleNotFound:(route)->

    status_404 = =>
      KDRouter::handleNotFound.call this, route

    status_301 = (redirectTarget)=>
      @handleRoute "/#{redirectTarget}", replaceState: yes

    KD.remote.api.JUrlAlias.resolve route, (err, target)->
      if err or not target? then status_404()
      else status_301 target

  getDefaultRoute:-> if KD.isLoggedIn() then '/Activity' else '/'

{'fraction_non_alphanumeric': 0.10997288339861404, 'fraction_numerical': 0.004820729135281711, 'mean_word_length': 3.0880541871921183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1186319', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1912, 'n_words': 532}