Skip to content

Instantly share code, notes, and snippets.

@vincentdchan
Last active February 1, 2018 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vincentdchan/206ba93ca9fe1ff8ab62728a075420e4 to your computer and use it in GitHub Desktop.
Save vincentdchan/206ba93ca9fe1ff8ab62728a075420e4 to your computer and use it in GitHub Desktop.
LittleReduxSimulator
class LittleReduxSimulator extends Component {
constructor(props) {
super(props);
this.state = this.props.init();
}
dispatch = value => {
this.setState(this.props.update(value));
}
render() {
return this.props.render({ dispatch: this.dispatch, state: this.state });
}
}
const feedbackButtonComponentGenerator = ({ dispatch, state }) => {
const handleClicked = e => {
switch (state.fetchStatus) {
case 'loaded':
dispatch('loading');
break;
case 'loading':
dispatch('loaded');
break;
}
}
const { fetchStatus } = state;
return <button onClick={handleClicked} className="group-feedback layout-row layout-cross-center layout-main-center">
<span><BrandLarkSmallLogo /></span>
{ fetchStatus === 'loaded' ? "入群反馈" : "加入中" }
</button>;
}
const docsVIPGroup = (
<div className="docsVIPGroup-container layout-column layout-cross-center">
<img className="lark-logo" src={BrandLarkLogo} width={48} height={48} />
<h1 className="header">Docs VIP 用户群</h1>
<LittleReduxSimulator
init={() => ({ fetchStatus: 'loaded' })}
update={(current, value) => ({ fetchStatus: value })}
render={feedbackButtonComponentGenerator}
/>
</div>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment