Created
May 29, 2016 05:41
-
-
Save awei01/69ecf9b722eeec825125438755ff932d to your computer and use it in GitHub Desktop.
example for issue on cerebral
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
const controller = Controller(Model({})); | |
function setFoo({ input, state }) { | |
state.set('example.foo', input.value); | |
} | |
const changeInput = [setFoo]; | |
const Module = (options = {}) => { | |
return (module, controller) => { | |
module.addState({ | |
foo: "original value" | |
}); | |
module.addSignals({ | |
changeInput | |
}); | |
}; | |
}; | |
controller.addModules({ | |
example: Module() | |
}) | |
@Cerebral({ | |
display: ['example', 'foo'] | |
}) | |
class InputControl extends React.Component { | |
render() { | |
return ( | |
<div> | |
<input type="text" value={ this.props.display } | |
onChange={ (e) => { this.props.signals.example.changeInput.sync({ value: e.target.value }); } } | |
/> | |
</div> | |
); | |
} | |
}; | |
ReactDOM.render( | |
( | |
<Container controller={controller}> | |
<InputControl/> | |
</Container> | |
), | |
document.getElementById('root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment