Skip to content

Commit

Permalink
Fix data fetching interval and log events
Browse files Browse the repository at this point in the history
  • Loading branch information
harshjv committed Oct 13, 2016
1 parent 4486fd3 commit 5d42faa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/app/actions/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import api from '../utils/api'

export default {
fetchData () {
console.log('Fetching data')

api((error, data) => {
if (error) throw new Error(error)

console.log('Data fetched successfully')

AppDispatcher.dispatch({
type: ActionTypes.COIN_DATA,
data: {
Expand Down
10 changes: 5 additions & 5 deletions src/app/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class Footer extends React.Component {
}

this.quit = this.quit.bind(this)
this.updateInterval = this.updateInterval.bind(this)
this.setUpdateInterval = this.setUpdateInterval.bind(this)
this.openGitHubLink = this.openGitHubLink.bind(this)
this.renderIntervalOptions = this.renderIntervalOptions.bind(this)
this.renderRightButtonGroup = this.renderRightButtonGroup.bind(this)
Expand All @@ -32,7 +32,7 @@ export default class Footer extends React.Component {
}

componentDidMount () {
this.updateInterval()
this.setUpdateInterval()()
}

quit () {
Expand All @@ -43,14 +43,14 @@ export default class Footer extends React.Component {
shell.openExternal(pkg.homepage)
}

updateInterval (interval = this.state.interval) {
setUpdateInterval (interval = this.state.interval) {
return () => {
this.setState({
interval: interval
})

if (this.updateIntervalHandler) clearInterval(this.updateIntervalHandler)
this.updateIntervalHandler = setInterval(() => Actions.fetchData, interval)
this.updateIntervalHandler = setInterval(Actions.fetchData, interval)
}
}

Expand All @@ -61,7 +61,7 @@ export default class Footer extends React.Component {
'active': interval === this.state.interval
})

return <button className={cls} key={interval} onClick={this.updateInterval(interval)}>{duration(interval)}</button>
return <button className={cls} key={interval} onClick={this.setUpdateInterval(interval)}>{duration(interval)}</button>
})
}

Expand Down

0 comments on commit 5d42faa

Please sign in to comment.