-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Warn when a inject has been not provided #5681
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
Conversation
src/core/instance/inject.js
Outdated
@@ -57,6 +57,8 @@ export function resolveInject (inject: any, vm: Component): ?Object { | |||
} | |||
source = source.$parent | |||
} | |||
process.env.NODE_ENV !== 'production' && typeof result[key] === 'undefined' && |
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.
maybe result[key]
just is undefined
!hasOwn(result, key)
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.
Thanks! I added this to a test and solved usingObject.keys
.
In the end solution is not result.hasOwnProperty(key)
or a result.hasOwnProperty && !result.hasOwnProperty(key)
because this failed some tests. Also Flow was reporting strange error, which required a change in var definition to: const result = (Object.create(null): Object)
.
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.
shared/util/hasOwn
src/core/instance/inject.js
Outdated
@@ -57,6 +57,8 @@ export function resolveInject (inject: any, vm: Component): ?Object { | |||
} | |||
source = source.$parent | |||
} | |||
process.env.NODE_ENV !== 'production' && typeof result[key] === 'undefined' && | |||
warn(`injection "${key}" not found`, vm) |
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.
capitalize Injection "${key}" not found
@lonelyclick there seems to be no consistency to start short warnings uppercase, some examples: This seems like a very low priority but we could change them to uppercase too. Would you like this, @posva? |
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.
use shared/util/hasOwn
@lonelyclick thanks! |
src/core/instance/inject.js
Outdated
@@ -3,6 +3,7 @@ | |||
import { hasSymbol } from 'core/util/env' | |||
import { warn } from '../util/index' | |||
import { defineReactive } from '../observer/index' | |||
import { hasOwn } from '../../shared/util' |
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.
can just use shared/util
instead because it's aliased
src/core/instance/inject.js
Outdated
@@ -57,6 +58,8 @@ export function resolveInject (inject: any, vm: Component): ?Object { | |||
} | |||
source = source.$parent | |||
} | |||
process.env.NODE_ENV !== 'production' && !hasOwn(result, key) && |
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.
let's use if
here for more than one conditions
#5628
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: