Fix bug: Don't produce closure for every item
This commit is contained in:
@@ -67,6 +67,8 @@ export default class CycleChart extends Component {
|
|||||||
data={this.state.columns}
|
data={this.state.columns}
|
||||||
renderItem={this.renderColumn}
|
renderItem={this.renderColumn}
|
||||||
keyExtractor={item => item.dateString}
|
keyExtractor={item => item.dateString}
|
||||||
|
initialNumToRender={15}
|
||||||
|
maxToRenderPerBatch={5}
|
||||||
>
|
>
|
||||||
</FlatList>
|
</FlatList>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ import slowlog from 'react-native-slowlog'
|
|||||||
|
|
||||||
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||||
const label = styles.column.label
|
const label = styles.column.label
|
||||||
|
const getFhmAndLtlInfo = setUpFertilityStatusFunc()
|
||||||
|
|
||||||
export default class DayColumn extends Component {
|
export default class DayColumn extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.getFhmAndLtlInfo = setUpFertilityStatusFunc()
|
slowlog(this, /.*/)
|
||||||
// slowlog(this, /.*/)
|
|
||||||
}
|
}
|
||||||
makeDayColumn(data, index) {
|
makeDayColumn(data, index) {
|
||||||
const {
|
const {
|
||||||
@@ -35,8 +35,7 @@ export default class DayColumn extends Component {
|
|||||||
} = data
|
} = data
|
||||||
const cycleDayNumber = getCycleDayNumber(dateString)
|
const cycleDayNumber = getCycleDayNumber(dateString)
|
||||||
const dateLabel = dateString.split('-').slice(1).join('-')
|
const dateLabel = dateString.split('-').slice(1).join('-')
|
||||||
// const nfpLineInfo = this.getFhmAndLtlInfo(dateString, temperature)
|
const nfpLineInfo = getFhmAndLtlInfo(dateString, temperature)
|
||||||
const nfpLineInfo = {}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<G onPress={() => this.passDateToDayView(dateString)}>
|
<G onPress={() => this.passDateToDayView(dateString)}>
|
||||||
|
|||||||
@@ -2,26 +2,26 @@ import { getCycleStatusForDay } from '../../lib/sympto-adapter'
|
|||||||
import { normalizeToScale } from './y-axis'
|
import { normalizeToScale } from './y-axis'
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
let cycleStatus
|
const cycle = {
|
||||||
let cycleStartDate
|
status: null
|
||||||
let noMoreCycles = false
|
}
|
||||||
|
|
||||||
function updateCurrentCycle(dateString) {
|
function updateCurrentCycle(dateString) {
|
||||||
cycleStatus = getCycleStatusForDay(dateString)
|
cycle.status = getCycleStatusForDay(dateString)
|
||||||
if(!cycleStatus) {
|
if(!cycle.status) {
|
||||||
noMoreCycles = true
|
cycle.noMoreCycles = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (cycleStatus.phases.preOvulatory) {
|
if (cycle.status.phases.preOvulatory) {
|
||||||
cycleStartDate = cycleStatus.phases.preOvulatory.start.date
|
cycle.startDate = cycle.status.phases.preOvulatory.start.date
|
||||||
} else {
|
} else {
|
||||||
cycleStartDate = cycleStatus.phases.periOvulatory.start.date
|
cycle.startDate = cycle.status.phases.periOvulatory.start.date
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dateIsInPeriOrPostPhase(dateString) {
|
function dateIsInPeriOrPostPhase(dateString) {
|
||||||
return (
|
return (
|
||||||
dateString >= cycleStatus.phases.periOvulatory.start.date
|
dateString >= cycle.status.phases.periOvulatory.start.date
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,15 +29,15 @@ export default function () {
|
|||||||
return (
|
return (
|
||||||
// we are only interested in days that have a preceding
|
// we are only interested in days that have a preceding
|
||||||
// temp
|
// temp
|
||||||
Object.keys(cycleStatus.phases).some(phaseName => {
|
Object.keys(cycle.status.phases).some(phaseName => {
|
||||||
return cycleStatus.phases[phaseName].cycleDays.some(day => {
|
return cycle.status.phases[phaseName].cycleDays.some(day => {
|
||||||
return day.temperature && day.date < dateString
|
return day.temperature && day.date < dateString
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
// and also a following temp, so we don't draw the line
|
// and also a following temp, so we don't draw the line
|
||||||
// longer than necessary
|
// longer than necessary
|
||||||
&&
|
&&
|
||||||
cycleStatus.phases.postOvulatory.cycleDays.some(day => {
|
cycle.status.phases.postOvulatory.cycleDays.some(day => {
|
||||||
return day.temperature && day.date > dateString
|
return day.temperature && day.date > dateString
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -51,13 +51,13 @@ export default function () {
|
|||||||
|
|
||||||
return function(dateString, temperature) {
|
return function(dateString, temperature) {
|
||||||
const ret = {}
|
const ret = {}
|
||||||
if (!cycleStatus && !noMoreCycles) updateCurrentCycle(dateString)
|
if (!cycle.status && !cycle.noMoreCycles) updateCurrentCycle(dateString)
|
||||||
if (noMoreCycles) return ret
|
if (cycle.noMoreCycles) return ret
|
||||||
|
|
||||||
if (dateString < cycleStartDate) updateCurrentCycle(dateString)
|
if (dateString < cycle.startDate) updateCurrentCycle(dateString)
|
||||||
if (noMoreCycles) return ret
|
if (cycle.noMoreCycles) return ret
|
||||||
|
|
||||||
const tempShift = cycleStatus.temperatureShift
|
const tempShift = cycle.status.temperatureShift
|
||||||
|
|
||||||
if (tempShift) {
|
if (tempShift) {
|
||||||
if (tempShift.firstHighMeasurementDay.date === dateString) {
|
if (tempShift.firstHighMeasurementDay.date === dateString) {
|
||||||
|
|||||||
Reference in New Issue
Block a user