-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify terminology #237
Clarify terminology #237
Conversation
This is more correct as-is. Thunks can take arguments. That doesn't make them action creators; they still return a function instead of an object. Also, they're not just for async side effects. |
FWIW, I think the first part of the comment more accurately reflects how I would describe them myself. Second comment seems off, though. The function with the |
Hi @timdorr, are you calling the outer function, inner function, or both a thunk? If the outer function in the code snippet I edited the comment for isn't an action creator, then what is a "thunk action creator"? And if the inner function isn't a thunk, then what is a "thunk async action"? The terminology is muddled right now and the parts I proposed changing aren't even internally consistent with the rest of the docs and that interpretation is inconsistent with all of the sources you link to:
The return value of This directly refers to the inner function as the thunk:
Redux documentation:
Redux thunk docs:
function not_a_thunk() {
// this one is a "thunk" because it defers work for later:
return function() {
console.log('do stuff now');
};
} The StackOverflow answers by you link to by @gaearon specifically describe the outer function in this scenario as an action creator.
export function showNotificationWithTimeout(text) {
return function (dispatch) {
const id = nextNotificationId++
dispatch(showNotification(id, text))
setTimeout(() => {
dispatch(hideNotification(id))
}, 5000)
}
}
// action creator
function loadData(userId) {
return dispatch => fetch(`http://data.com/${userId}`)
.then(res => res.json())
.then(
data => dispatch({ type: 'LOAD_DATA_SUCCESS', data }),
err => dispatch({ type: 'LOAD_DATA_FAILURE', err })
);
} https://medium.com/fullstack-academy/thunks-in-redux-the-basics-85e538a3fe60 const thunkedLogin = () => // action creator, when invoked…
() => // …returns a thunk, which when invoked…
axios.get('/api/auth/me') // …performs the actual effect.
.then(res => res.data)
.then(user => {
store.dispatch(simpleLogin(user))
}) |
FWIW, I personally dislike the phrase "async action" and want to remove it in the upcoming docs revamp. A thunk function isn't an "action". It's not a plain object, and it doesn't have a |
Thanks @markerikson.
I want to come back to that after getting the thunk vs. action creator part straight and understand what seems off to you. FWIW I don't think "async action" would really be problematic if all of the terminology was used consistently, e.g. "async action creator", "async action", "thunk action creator", "thunk". But what do you think would be a better general term for these dispatchable things that could be a thunk, promise, or ...? So is someone going to reopen this since the content I edited is clearly inconsistent with other parts of your own docs and all of the sources you link to? The dismissive handling of this is disappointing. |
I'm not sure there's a single specific term that would be used for "passing other things to Yeah, lemme tweak the wording on that second paragraph a bit, and then I'll merge this. |
Thanks @markerikson, I appreciate that 🙌 |
Currently it describes the action creator as the thunk.