-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
fix(runtime-core): app.provide throws a warning when assigning the same value. #10337
Conversation
Size ReportBundles
Usages
|
441334f
to
cf0ef58
Compare
…ning should be thrown
warn( | ||
`App already provides property with key "${String(key)}". ` + | ||
`It will be overwritten with the new value.`, | ||
) | ||
} | ||
|
||
context.provides[key as string | symbol] = value | ||
if (isValueChanged) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (isValueChanged) {
could be merged with previous if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting to put it inside an else
block? Since the value is already the same, there is no need to perform the assignment again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no
if (isValueChanged) {
if (...) warn()
context.provides[key as string | symbol] = newVal
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it.
Perhaps the warning needs to be optimized? I think if the same value is assigned, it should only warn the user that the same value already exists, instead of warning the user about overwriting the old value with a new one. |
I don't think this is necessary. Providing the same value twice is pointless and should also be avoided if possible so a warning is appropriate. |
If providing the same value to app.provide, no warning should be thrown.