Last active
August 29, 2015 14:26
-
-
Save micmmakarov/0e1fdfbcc3e1b251ca68 to your computer and use it in GitHub Desktop.
Magic input for reactJS, supporting deep path binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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