-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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 provide isn't reactive with a single array, Fix #5223 #5229
Conversation
4843602
to
f7630c4
Compare
One thing I don't want with provide/inject is child modifying ancestor's data. If Injected properties were kept non-reactive intentionally. Perhaps @yyx990803 could explain better. |
https://facebook.github.io/react/docs/context.html#updating-context
should we warn when the context is changed? |
f7630c4
to
3507eb8
Compare
Currently, reactive objects can be provided. https://jsfiddle.net/m0fyr6z1/3/ - In this example, you see, child re-renders if array is changed in parent component. IMO, rather than setting provided injections (current implementation) or defining reactive injections (this PR), it would be better to add enumerable, non-configurable & read-only injections. |
/ping @yyx990803 – Your input required. |
|
src/core/instance/inject.js
Outdated
@@ -29,7 +31,14 @@ export function initInjections (vm: Component) { | |||
let source = vm | |||
while (source) { | |||
if (source._provided && provideKey in source._provided) { | |||
vm[key] = source._provided[provideKey] | |||
defineReactive(vm, key, source._provided[provideKey], () => { | |||
warn( |
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.
make sure to prefix warnings with process.env.NODE_ENV
check :)
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.
done
0ce6ce6
to
4a5733c
Compare
Overriding the setter makes this PR introduce a BC. |
It doesn't because it was not reactive anyway. |
In the project I'm working on, I did the following: export default {
inject: ['_searchStore'],
props: {
searchStore: {
type: Object,
default () {
return this._searchStore
}
}
}
} Which will now break if I'm not mistaken. |
* fix provide isn't reactive with a single array - Fix vuejs#5223 * add warning when injections has been modified
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
#5223