Skip to content

Instantly share code, notes, and snippets.

@awei01
Created May 29, 2016 05:41
Show Gist options
  • Save awei01/69ecf9b722eeec825125438755ff932d to your computer and use it in GitHub Desktop.
Save awei01/69ecf9b722eeec825125438755ff932d to your computer and use it in GitHub Desktop.
example for issue on cerebral
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