Replace binds with lambdas

This commit is contained in:
Julia Friesel
2018-08-28 08:40:09 +02:00
parent b09137772c
commit 398c726d94
4 changed files with 24 additions and 22 deletions
+14 -15
View File
@@ -19,28 +19,27 @@ export default class App extends Component {
this.state = {
currentPage: 'Home'
}
const handleBackButtonPress = function() {
if (this.state.currentPage === 'Home') return false
if (isSymptomView(this.state.currentPage)) {
this.navigate('CycleDay', {cycleDay: this.state.currentProps.cycleDay})
} else {
this.navigate('Home')
}
return true
}.bind(this)
this.backHandler = BackHandler.addEventListener('hardwareBackPress', handleBackButtonPress)
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonPress)
}
componentWillUnmount() {
this.backHandler.remove()
}
navigate(pageName, props) {
navigate = (pageName, props) => {
this.setState({currentPage: pageName, currentProps: props})
}
handleBackButtonPress = () => {
if (this.state.currentPage === 'Home') return false
if (isSymptomView(this.state.currentPage)) {
this.navigate('CycleDay', { cycleDay: this.state.currentProps.cycleDay })
} else {
this.navigate('Home')
}
return true
}
render() {
const page = {
Home, Calendar, CycleDay, Chart, Settings, Stats, ...symptomViews
@@ -51,12 +50,12 @@ export default class App extends Component {
{this.state.currentPage != 'CycleDay' && <Header title={titles[this.state.currentPage]} />}
{React.createElement(page, {
navigate: this.navigate.bind(this),
navigate: this.navigate,
...this.state.currentProps
})}
{!isSymptomView(this.state.currentPage) &&
<Menu navigate={this.navigate.bind(this)} />
<Menu navigate={this.navigate} />
}
</View>
)
+2 -2
View File
@@ -25,7 +25,7 @@ export default class CalendarView extends Component {
bleedingDaysSortedByDate.removeListener(this.setStateWithCalFormattedDays)
}
passDateToDayView(result) {
passDateToDayView = (result) => {
const cycleDay = getOrCreateCycleDay(result.dateString)
const navigate = this.props.navigate
navigate('CycleDay', { cycleDay })
@@ -34,7 +34,7 @@ export default class CalendarView extends Component {
render() {
return (
<CalendarList
onDayPress={this.passDateToDayView.bind(this)}
onDayPress={this.passDateToDayView}
markedDates={this.state.bleedingDaysInCalFormat}
markingType={'period'}
/>
+6 -3
View File
@@ -31,7 +31,7 @@ export default class CycleDayOverView extends Component {
}
}
goToCycleDay(target) {
goToCycleDay = (target) => {
const localDate = LocalDate.parse(this.state.cycleDay.date)
const targetDate = target === 'before' ?
localDate.minusDays(1).toString() :
@@ -55,7 +55,7 @@ export default class CycleDayOverView extends Component {
isCycleDayOverView={true}
cycleDayNumber={cycleDayNumber}
date={cycleDay.date}
goToCycleDay={this.goToCycleDay.bind(this)}
goToCycleDay={this.goToCycleDay}
/>
<ScrollView>
<View style={styles.symptomBoxesView}>
@@ -134,7 +134,10 @@ function getLabel(symptomName, symptom) {
cervix: cervix => {
let cervixLabel = []
if (cervix.opening > -1 && cervix.firmness > -1) {
cervixLabel.push(openingLabels[cervix.opening], firmnessLabels[cervix.firmness])
cervixLabel.push(
openingLabels[cervix.opening],
firmnessLabels[cervix.firmness]
)
if (cervix.position > -1) {
cervixLabel.push(positionLabels[cervix.position])
}
+2 -2
View File
@@ -8,7 +8,7 @@ import styles, { iconStyles } from '../styles'
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
export default class Menu extends Component {
makeMenuItem({ title, icon, onPress}, i) {
makeMenuItem = ({ title, icon, onPress}, i) => {
return (
<TouchableOpacity
onPress={onPress}
@@ -36,7 +36,7 @@ export default class Menu extends Component {
{ title: 'Chart', icon: 'chart-line', onPress: () => this.goTo('Chart') },
{ title: 'Stats', icon: 'chart-pie', onPress: () => this.goTo('Stats') },
{ title: 'Settings', icon: 'settings', onPress: () => this.goTo('Settings') },
].map(this.makeMenuItem.bind(this))}
].map(this.makeMenuItem)}
</View >
)
}