Why does the code here need to be written using ternary judgment in Vuex3 store.js dispatch method #11300
Unanswered
miyagipipi
asked this question in
Help/Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
const result = entry.length > 1 ? Promise.all(entry.map(handler => handler(payload))) : entry[0](payload)
In Vuex3 /src/store.js dispatch method.
I saw this source code before and thought it was specifically optimized, for example, when
entry.length === 1
, usingPromise.all()
would require more resources thanentry[0](payload)
. But I think the cost difference between the two should be negligible whenentry.length === 1
.So I want to know why ternary judgment is specifically used here, instead of directly using
Promise.all()
method?Beta Was this translation helpful? Give feedback.
All reactions