-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
73 lines (61 loc) · 1.52 KB
/
example.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React from 'react'
import ReactDom from 'react-dom'
import {
createClient,
debugLog,
withMetricsServiceContext,
withMetricsServiceClient,
metricsServiceClick,
} from './src'
import googleAnalytics from './src/dispatchers/google-analytics'
/* eslint-disable react/prefer-stateless-function, react/no-multi-comp */
const client = createClient({
dispatchers: [debugLog, googleAnalytics({ trackingId: 'UA-000000-01' })],
})
class MyComponent extends React.Component {
static propTypes = {
metricsServiceClient: React.PropTypes.object,
}
render() {
return (
<div
style={{ backgroundColor: 'LightGreen' }}
onClick={() => this.props.metricsServiceClient.click('here')}
>
{'MyComponent'}
</div>
)
}
}
const EnhancedMyComponent = withMetricsServiceClient()(MyComponent)
class OtherComponent extends React.Component {
static propTypes = {
metricsServiceClient: React.PropTypes.object,
}
render() {
return (
<div
style={{ backgroundColor: 'LightBlue' }}
>
{'OtherComponent'}
</div>
)
}
}
const EnhancedOtherComponent = metricsServiceClick('click', 'other-event')(OtherComponent)
class App extends React.Component {
render() {
return (
<div>
<EnhancedMyComponent />
<EnhancedOtherComponent />
</div>
)
}
}
const EnhancedApp = withMetricsServiceContext({ client })(App)
const div = document.createElement('div')
document.body.appendChild(div)
ReactDom.render((
<EnhancedApp />
), div)