Created
August 1, 2018 10:54
-
-
Save SanchitB23/e19f26e219af8f9de57c34f91eeaeada to your computer and use it in GitHub Desktop.
Do you understand this code?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loadItems(day) { | |
setTimeout(() => { | |
for (let i = -15; i < 85; i++) { | |
const time = day.timestamp + i * 24 * 60 * 60 * 1000; | |
const strTime = this.timeToString(time); | |
// console.log('time', time); | |
// console.log('day', day); | |
// console.log('strTime', strTime); | |
if (!this.state.items[strTime]) { | |
this.state.items[strTime] = []; | |
const numItems = Math.floor(Math.random() * 5); | |
for (let j = 0; j < numItems; j++) { | |
// console.log(dummy.data[j]); | |
this.state.items[strTime].push({ | |
name: `Item for${strTime}`, | |
day, | |
dummy: dummy.data[j], | |
height: Math.max(50, Math.floor(Math.random() * 150)) | |
}); | |
} | |
} | |
} | |
//arr of obj of displayed | |
console.log('.', this.state.items); | |
const newItems = {}; | |
Object.keys(this.state.items).forEach(key => { newItems[key] = this.state.items[key]; }); | |
this.setState({ | |
items: newItems | |
}); | |
}, 1000); | |
console.log(`Load Items for ${day.year}-${day.month}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment