mWater / mwater-forms

Forms controls for mWater
GNU Lesser General Public License v3.0
3 stars 5 forks source link

See if cascading on mount changes work #110

Closed grassick closed 8 years ago

grassick commented 8 years ago

What happens in a large immutable structure where multiple component modify it on mount?

grassick commented 8 years ago
class ChangeOnMount extends React.Component
  componentWillMount: ->
    val = {}
    val[@props.k] = @props.v
    @props.onChange(_.extend({}, @props.value, val))

  render: ->
    H.div null,
      JSON.stringify(@props.value)

class ChangeOnMountParent extends React.Component
  constructor: ->
    @state = {
      value: { test: 0 }
    }

  handleChange: (value) => 
    console.log "handleChange: " + JSON.stringify(value)
    @setState(value: value)

  render: ->
    console.log JSON.stringify(@state.value)

    H.div null,
      R ChangeOnMount, value: @state.value, onChange: @handleChange, k: "a", v: 1
      R ChangeOnMount, value: @state.value, onChange: @handleChange, k: "b", v: 2
      R ChangeOnMount, value: @state.value, onChange: @handleChange, k: "c", v: 3
      R ChangeOnMount, value: @state.value, onChange: @handleChange, k: "d", v: 4
{"test":0,"d":4}
{"test":0,"d":4}
{"test":0,"d":4}
{"test":0,"d":4}
grassick commented 8 years ago

So no, but:

    _.defer () =>
      val = {}
      val[@props.k] = @props.v
      @props.onChange(_.extend({}, @props.value, val))

does work.

Problem is there are 4 setstates at beginning and no re-render until later. Will affect how we handle the "remove all answers that are invisible" problem. Should be done at top level, perhaps?