Skip to content

Instantly share code, notes, and snippets.

@yuitowest
Created March 28, 2017 08:43
Show Gist options
  • Save yuitowest/4932f9be446cca18373d01043c2d4049 to your computer and use it in GitHub Desktop.
Save yuitowest/4932f9be446cca18373d01043c2d4049 to your computer and use it in GitHub Desktop.
React Native with Flumpt
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
TouchableHighlight,
View
} from 'react-native';
import {withFlux, dispatchable} from 'flumpt'
@dispatchable
class CounterIncrement extends Component {
onClick(e) {
console.log('click');
this.context.dispatch('increment')
}
render() {
return <TouchableHighlight onPress={this.onClick.bind(this)}><Text>+1</Text></TouchableHighlight>
}
}
@withFlux((update, on) => {
on('increment', () => {
update(state => {
return {count: state.count + 1}
})
})
}, {count: 0})
export default class FlumptExample extends Component {
render() {
return (
<View style={styles.container}>
<Text>{this.props.count}</Text>
<CounterIncrement/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('FlumptExample', () => FlumptExample);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment