Created
August 20, 2016 04:03
-
-
Save drewrawitz/231ccc56bd442dae0ce009d23cd28373 to your computer and use it in GitHub Desktop.
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
export const updateAlert = (alert, message) => { | |
return { | |
type: 'UPDATE_ALERT', | |
alert, | |
message | |
} | |
} | |
export const updateAlertThenDelete = (alert, message) => { | |
return function (dispatch) { | |
return dispatch( | |
updateAlert(alert, message).then(() => { | |
console.log('done'); | |
}) | |
) | |
} | |
} |
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
this.props.updateAlertThenDelete('error', ERROR_MESSAGE) |
@ddsol, you're right. I think I was overthinking this. I don't even need a callback in this instance.. all I need to do is:
waitTurn() {
const ERROR_MESSAGE = 'Please wait your turn.';
this.props.updateAlert('error', ERROR_MESSAGE)
setTimeout(() => {
console.log('remove alert code here');
}, 5000)
}
Thank you for explaining everything to me, it's now starting to make sense. I appreciate it!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updateAlert
returns an object with 3 properties. It returns this object whenever you call the function.then
is not one of the properties of the object returned. Therefore you cannot callthen(...)
. Sincethen
is undefined it isn't a function/method. Presumably you're trying to wait on a pendingPromise
but nowhere in your code is such a promise created. Now that you only need promises or callbacks when you need to wait for something like a network request. In your code no such waitable task is to be found. But let's say that you had such a task and let's sayupdateAlert
did in fact return a promise. You would be callingthen
on it and the handler function does aconsole.log
. The result of thethen
call is another promise, one that always resolves, eventually, toundefined
because yourthen
handler doesn't return anything. Next you're passing this promise todispatch
which has no idea what to do with a promise and will throw an error.