Skip to content

Instantly share code, notes, and snippets.

@Godefroy
Created March 1, 2020 17:19
Show Gist options
  • Save Godefroy/de8f8e5cb2d9e5a996ef7d2147520b23 to your computer and use it in GitHub Desktop.
Save Godefroy/de8f8e5cb2d9e5a996ef7d2147520b23 to your computer and use it in GitHub Desktop.
export function incrementAsync(n) {
return async (dispatch, getState) => {
console.log('initial count', getState().counter.count)
dispatch({ type: 'COUNTER_COUNTING', counting: true })
for (let i = 1; i <= n; i++) {
dispatch({ type: 'COUNTER_INCREMENT', n: 1 })
await new Promise(resolve => setTimeout(resolve, 500))
}
dispatch({ type: 'COUNTER_COUNTING', counting: false })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment