Skip to content

Instantly share code, notes, and snippets.

@micmmakarov
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micmmakarov/0e1fdfbcc3e1b251ca68 to your computer and use it in GitHub Desktop.
Save micmmakarov/0e1fdfbcc3e1b251ca68 to your computer and use it in GitHub Desktop.
Magic input for reactJS, supporting deep path binding
MagicInput = React.createClass
onChange: (e) ->
state = @props.binding[0].state
Sonar.changeByArray state, @path, e.target.value
@props.binding[0].setState state
getValue: ->
value = @props.binding[0].state
@path ||= @props.binding[1].split('.')
i = 0
while i < @path.length
value = value[@path[i]]
i++
value
render: ->
React.createElement 'input',
type: 'input'
onChange: @onChange
value: @getValue()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment