Skip to content

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

Merged
merged 9 commits into from
May 29, 2017

Conversation

maciej-ka
Copy link
Contributor

#5628

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

@@ -57,6 +57,8 @@ export function resolveInject (inject: any, vm: Component): ?Object {
}
source = source.$parent
}
process.env.NODE_ENV !== 'production' && typeof result[key] === 'undefined' &&
Copy link
Contributor

@lonelyclick lonelyclick May 16, 2017

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)

Copy link
Contributor Author

@maciej-ka maciej-ka May 16, 2017

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).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shared/util/hasOwn

@@ -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)
Copy link
Contributor

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

@maciej-ka
Copy link
Contributor Author

@lonelyclick there seems to be no consistency to start short warnings uppercase, some examples:
'infinite update loop'
'duplicate attribute'
'v-else use on element'
... and much more

This seems like a very low priority but we could change them to uppercase too. Would you like this, @posva?

Copy link
Contributor

@lonelyclick lonelyclick left a 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

@maciej-ka
Copy link
Contributor Author

@lonelyclick thanks!

@@ -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'
Copy link
Member

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

@@ -57,6 +58,8 @@ export function resolveInject (inject: any, vm: Component): ?Object {
}
source = source.$parent
}
process.env.NODE_ENV !== 'production' && !hasOwn(result, key) &&
Copy link
Member

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

@yyx990803 yyx990803 merged commit b182ac4 into vuejs:dev May 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants