-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
App.js
161 lines (143 loc) 路 3.89 KB
/
App.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import React, { Component } from 'react';
import flowRight from 'lodash.flowright';
import { Provider, connect } from 'react-redux';
import classNames from 'classnames';
// Import adapter from '@flopflip/launchdarkly-adapter';
// import adapter, { updateFlags } from '@flopflip/memory-adapter';
import adapter, { updateFlags } from '@flopflip/memory-adapter';
import {
ConfigureFlopFlip,
branchOnFeatureToggle,
injectFeatureToggle,
ToggleFeature,
} from '@flopflip/react-broadcast';
// Change to `from '@flopflip/react-broadcast'` and everything will just work wtihout redux
import {
increment,
incrementAsync,
decrement,
decrementAsync,
} from './modules/counter';
import logo from './logo.svg';
import store from './store';
import './App.css';
import allFlags, {
INCREMENT_ASYNC_BUTTON,
DECREMENT_ASYNC_BUTTON,
INCREMENT_SYNC_BUTTON,
} from './flags';
const UntoggledFeature = () => <h6>Disabled Feature</h6>;
const IncrementAsyncButton = props => (
<button
type="button"
disabled={props.isIncrementing}
onClick={props.incrementAsync}
>
Increment Async
</button>
);
const FeatureToggledIncrementAsyncButton = flowRight(
branchOnFeatureToggle({ flag: INCREMENT_ASYNC_BUTTON }, UntoggledFeature)
)(IncrementAsyncButton);
const IncrementSyncButton = props => (
<button
type="button"
className={classNames({
'incrementSyncButton--disabled': props.syncButtonStyle === false,
'incrementSyncButton--yellow': props.syncButtonStyle === 'yellow',
'incrementSyncButton--blue': props.syncButtonStyle === 'blue',
'incrementSyncButton--purple': props.syncButtonStyle === 'purple',
})}
disabled={props.isIncrementing}
onClick={props.increment}
>
Increment
</button>
);
const FeatureToggledIncrementSyncButton = injectFeatureToggle(
INCREMENT_SYNC_BUTTON,
'syncButtonStyle'
)(IncrementSyncButton);
const Counter = props => (
<div>
<h1>Count around</h1>
<p>Count: {props.count}</p>
<div>
<FeatureToggledIncrementSyncButton
increment={props.increment}
disabled={props.isIncrementing}
/>
<br />
<FeatureToggledIncrementAsyncButton
incrementAsync={props.incrementAsync}
isIncrementing={props.isIncrementing}
/>
</div>
<div>
<button
type="button"
disabled={props.isDecrementing}
onClick={props.decrement}
>
Decrementing
</button>
<br />
<ToggleFeature
flag={DECREMENT_ASYNC_BUTTON}
untoggledComponent={UntoggledFeature}
>
<button
type="button"
disabled={props.isDecrementing}
onClick={props.decrementAsync}
>
Decrement Async
</button>
</ToggleFeature>
</div>
</div>
);
const mapStateToProps = state => ({
count: state.counter.count,
isIncrementing: state.counter.isIncrementing,
isDecrementing: state.counter.isDecrementing,
});
const mapDispatchToProps = {
increment,
incrementAsync,
decrement,
decrementAsync,
};
const ConnectedCounter = connect(mapStateToProps, mapDispatchToProps)(Counter);
class App extends Component {
state = {
hasError: false,
};
static getDerivedStateFromError() {
return { hasError: true };
}
componentDidCatch(error, info) {
console.log(error, info);
}
render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return <h1>Something went wrong.</h1>;
}
return (
<Provider store={store}>
<ConfigureFlopFlip adapter={adapter} defaultFlags={allFlags}>
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to flopflip</h2>
</div>
<ConnectedCounter />
</div>
</ConfigureFlopFlip>
</Provider>
);
}
}
window.updateFlags = updateFlags;
export default App;