-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (34 loc) · 950 Bytes
/
index.js
File metadata and controls
41 lines (34 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// @flow
import React from 'react'
import ReactDom from 'react-dom'
import {
routine,
setState,
componentWillMount,
createHandlers
} from '../dist/react-routine.umd'
const controller = function*() {
// Get the initial props
const initial = yield componentWillMount()
// Set the initial state
yield setState({ value: initial.props.value })
// Create a change handler we can listen to
const { handlers } = yield createHandlers({ onChange: e => e.target.value })
while (true) {
// Wait for change handler
const { result } = yield handlers.onChange
// Set the new state
yield setState({ value: result })
}
}
const Component = props => (
<div>
<h1>{props.value}</h1>
<input value={props.value} onChange={props.onChange} />
</div>
)
const EnhancedComponent = routine(controller)(Component)
ReactDom.render(
<EnhancedComponent value="React Routine" />,
(document.getElementById('root'): any)
)