<commit_before>React = require 'react/lib/ReactWithAddons'
_ = require 'underscore'
Bacon = require 'bacon.model'

component_id = 1

createIdentityClass = (args...) ->
  cls = React.createClass args...
  prefix = cls.displayName ? 'identity'
  (props, args...) ->
    props ?= {}
    props.key = "#{prefix}_#{component_id++}"
    cls props, args...

generate_component_id = -> component_id++

ObservableMixin =
  #get_observable: -> @props.observable
  getInitialState: ->
    value = null
    observable = @get_observable?() ? @props.observable
    observable: observable
    # there might already be a value, so the onValue callback can be called inside getInitialState
    unsubscribe: observable.onValue (v) =>
      @setState value: v
      value = v
    value: value
  componentWillUnmount: ->
    @state.unsubscribe()

SimpleObservableComponent = createIdentityClass
  displayName: 'SimpleObservableComponent'
  mixins: [ObservableMixin]
  render: ->
    React.DOM.div {}, @state.value

SimpleLayoutComponent = createIdentityClass
  displayName: 'SimpleLayoutComponent'
  mixins: [React.addons.PureRenderMixin]
  render: ->
    React.DOM.div {}, @props.children

PropsModelComponent = createIdentityClass
  displayName: 'PropsModelComponent'
  mixins: [ObservableMixin]
  get_observable: -> @props.child_props
  render: -> @props.constructor @state.value

_.extend exports, {PropsModelComponent, ObservableMixin, SimpleLayoutComponent, createIdentityClass, generate_component_id}, React<commit_msg>createIdentityClass was a bad idea<commit_after>React = require 'react/lib/ReactWithAddons'
_ = require 'underscore'
Bacon = require 'bacon.model'

component_id = 1

createIdentityClass = (args...) ->
  cls = React.createClass args...
  prefix = cls.displayName ? 'identity'
  (props, args...) ->
    props ?= {}
    props.key = "#{prefix}_#{component_id++}"
    cls props, args...

generate_component_id = -> component_id++

ObservableMixin =
  #get_observable: -> @props.observable
  getInitialState: ->
    value = null
    observable = @get_observable?() ? @props.observable
    observable: observable
    # there might already be a value, so the onValue callback can be called inside getInitialState
    unsubscribe: observable.onValue (v) =>
      @setState value: v
      value = v
    value: value
  componentWillUnmount: ->
    @state.unsubscribe()

SimpleObservableComponent = createIdentityClass
  displayName: 'SimpleObservableComponent'
  mixins: [ObservableMixin]
  render: ->
    React.DOM.div {}, @state.value

SimpleLayoutComponent = React.createClass
  displayName: 'SimpleLayoutComponent'
  mixins: [React.addons.PureRenderMixin]
  render: ->
    React.DOM.div {}, @props.children

PropsModelComponent = createIdentityClass
  displayName: 'PropsModelComponent'
  mixins: [ObservableMixin]
  get_observable: -> @props.child_props
  render: -> @props.constructor @state.value

_.extend exports, {PropsModelComponent, ObservableMixin, SimpleLayoutComponent, createIdentityClass, generate_component_id}, React
{'fraction_non_alphanumeric': 0.11257840871574777, 'fraction_numerical': 0.0006602839220864972, 'mean_word_length': 4.334507042253521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '2188008', 'n_tokens_mistral': 902, 'n_tokens_neox': 909, 'n_words': 209}