Andre Medeiros
"Someone else is responsible for me."
// speaker.js
getEndOfSpeechPromise()
.then(function () {
participants.forEach(function (participant) {
participant.goGetBeer();
});
});
// participant1.js
speaker.endOfSpeechEvents.subscribe(function () {
goGetBeer();
});
// participant2.js
speaker.endOfSpeechEvents.subscribe(function () {
tweet('Pretty decent presentation.');
});
// Timer is PROACTIVE
var Timer = React.createClass({
getInitialState: function() {
return {secondsElapsed: 0};
},
tick: function() {
// State is PASSIVE
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
},
componentDidMount: function() {
this.interval = setInterval(this.tick, 1000);
},
componentWillUnmount: function() {
clearInterval(this.interval);
},
render: function() { // Rendering is REACTIVE
return (
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>
);
}
});
React.render(<Timer />, mountNode);
var HelloModel = Cycle.createModel(['changeName$'], function (intent) {
return {name$: intent.changeName$.startWith('')};
});
var HelloView = Cycle.createView(['name$'], function (model) {
return {
vtree$: model.name$
.map(function (name) {
return h('div', {}, [
h('label', 'Name:'),
h('input', {
'attributes': {'type': 'text'},
'ev-input': 'inputText$'
}),
h('hr'),
h('h1', 'Hello ' + name)
]);
}),
events: ['inputText$']
};
});
var HelloIntent = Cycle.createIntent(['inputText$'], function (view) {
return {
changeName$: view.inputText$.map(function (ev) { return ev.target.value; })
};
});
Cycle.createRenderer('.js-container').inject(HelloView);
Cycle.circularInject(HelloModel, HelloView, HelloIntent);