<commit_before>require! <[ bluebird ./routes ./cursor ./dom ./server-rendering ]>
{span} = dom

app-component = React.create-factory React.create-class do
  display-name: 'reflex-application'

  get-initial-state: ->
    component: @props.component
    context: @props.context
    app-state: @props.initial-state

  render: ->
    if @state.component
      that context: @state.context, app-state: @state.app-state
    else
      span "Page not found."

module.exports =
  # define an application instance
  create: (config) ->
    do
      # start the application
      start: ->
        path = (location.pathname + location.search + location.hash)
        root-dom-node = document.get-element-by-id "application"

        server-state = JSON.parse root-dom-node.get-attribute 'data-reflex-app-state'
        initial-state = cursor (server-state or config.get-initial-state!)

        [route-component, context, _] = routes.resolve path, config.routes!
        root-element = app-component initial-state: initial-state, component: route-component, context: context

        config.start initial-state, (->)

        root = React.render root-element, root-dom-node

        initial-state.on-change -> root.set-state app-state: initial-state
        routes.start config.routes!, root, initial-state

      # render a particular route to string
      # returns a promise of [state, body]
      render: (path) ->
        new bluebird (res, rej) ->
          initial-state = cursor config.get-initial-state!<commit_msg>Change back to factory/create-element in application component.<commit_after>require! <[ bluebird ./routes ./cursor ./dom ./server-rendering ]>
{span} = dom

app-component = React.create-factory React.create-class do
  display-name: 'reflex-application'

  get-initial-state: ->
    component: @props.component
    context: @props.context
    app-state: @props.initial-state

  render: ->
    if @state.component
      react.create-element that, context: @state.context, app-state: @state.app-state
    else
      span "Page not found."

module.exports =
  # define an application instance
  create: (config) ->
    do
      # start the application
      start: ->
        path = (location.pathname + location.search + location.hash)
        root-dom-node = document.get-element-by-id "application"

        server-state = JSON.parse root-dom-node.get-attribute 'data-reflex-app-state'
        initial-state = cursor (server-state or config.get-initial-state!)

        [route-component, context, _] = routes.resolve path, config.routes!
        root-element = app-component initial-state: initial-state, component: route-component, context: context

        config.start initial-state, (->)

        root = React.render root-element, root-dom-node

        initial-state.on-change -> root.set-state app-state: initial-state
        routes.start config.routes!, root, initial-state

      # render a particular route to string
      # returns a promise of [state, body]
      render: (path) ->
        new bluebird (res, rej) ->
          initial-state = cursor config.get-initial-state!
{'fraction_non_alphanumeric': 0.12121212121212122, 'fraction_numerical': 0.0, 'mean_word_length': 2.725090036014406, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '2596905', 'n_tokens_mistral': 895, 'n_tokens_neox': 884, 'n_words': 226}