-
Notifications
You must be signed in to change notification settings - Fork 668
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
Add provided/inject support for Composition API components #1354
Merged
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
913f047
Support composition api variable for provider
661ecec
Add files for flow support in vscode and updated flow to 0.111.x
3586336
Add test for injection on composition api component.
8667d19
Fix prettier on vscode workspace settings.
eef7ae6
More prettier changes
07e5eef
Removed unused imports from injection composition vue file
cf843c9
Even more prettier.
70e8651
Update for PR comments
4286b7e
Support composition api variable for provider
4c14b61
Add files for flow support in vscode and updated flow to 0.111.x
142fe1d
Add test for injection on composition api component.
f2d0524
Fix prettier on vscode workspace settings.
dc5d030
More prettier changes
ba37406
Removed unused imports from injection composition vue file
ad98384
Even more prettier.
a0f1661
Update for PR comments
58b5fc5
Fix linting
9552017
Revert flow to fix issues
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"javascript.validate.enable": false, | ||
"flow.pathToFlow": "${workspaceFolder}/node_modules/.bin/flow" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/resources/components/component-with-inject-composition.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<template> | ||
<div>{{ fromMount }}</div> | ||
</template> | ||
|
||
<script> | ||
import { createComponent, inject, ref } from '@vue/composition-api' | ||
|
||
export default createComponent({ | ||
name: 'component-with-inject-composition', | ||
setup: () => { | ||
const fromMount = inject('fromMount') | ||
const setInSetup = ref('created') | ||
|
||
return { | ||
fromMount, | ||
setInSetup | ||
} | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { config } from '~vue/test-utils' | ||
import { createLocalVue } from '~vue/test-utils' | ||
import ComponentWithInject from '~resources/components/component-with-inject.vue' | ||
import CompositionComponentWithInject from '~resources/components/component-with-inject-composition.vue' | ||
import { injectSupported } from '~resources/utils' | ||
import { describeWithShallowAndMount } from '~resources/utils' | ||
import { itDoNotRunIf, itSkipIf } from 'conditional-specs' | ||
import VueCompositionApi from '@vue/composition-api' | ||
|
||
describeWithShallowAndMount('options.provide', mountingMethod => { | ||
let configProvideSave | ||
|
@@ -58,6 +61,23 @@ describeWithShallowAndMount('options.provide', mountingMethod => { | |
} | ||
) | ||
|
||
itDoNotRunIf( | ||
!injectSupported || mountingMethod.name === 'renderToString', | ||
'supports setup in composition api component', | ||
() => { | ||
if (!injectSupported) return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the point of this? It is already checked above? |
||
|
||
const localVue = createLocalVue() | ||
localVue.use(VueCompositionApi) | ||
const wrapper = mountingMethod(CompositionComponentWithInject, { | ||
provide: { fromMount: '_' }, | ||
localVue | ||
}) | ||
|
||
expect(wrapper.vm.setInSetup).to.equal('created') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this connected to provide/inject? |
||
} | ||
) | ||
|
||
itSkipIf( | ||
mountingMethod.name === 'renderToString', | ||
'injects the provide from the config', | ||
|
@@ -86,8 +106,23 @@ describeWithShallowAndMount('options.provide', mountingMethod => { | |
} | ||
) | ||
|
||
itDoNotRunIf( | ||
!injectSupported, | ||
'injects in a composition api component', | ||
() => { | ||
const localVue = createLocalVue() | ||
localVue.use(VueCompositionApi) | ||
const wrapper = mountingMethod(CompositionComponentWithInject, { | ||
provide: { fromMount: '_' }, | ||
localVue | ||
}) | ||
|
||
expect(wrapper.html()).to.contain('_') | ||
} | ||
) | ||
|
||
it('config with function throws', () => { | ||
config.provide = () => {} | ||
config.provide = () => { } | ||
Stoom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
expect(() => { | ||
mountingMethod(ComponentWithInject, { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -810,6 +810,13 @@ | |
source-map "^0.5.6" | ||
vue-template-es2015-compiler "^1.6.0" | ||
|
||
"@vue/composition-api@^0.3.2": | ||
version "0.3.2" | ||
resolved "https://registry.yarnpkg.com/@vue/composition-api/-/composition-api-0.3.2.tgz#2d797028e489bf7812f08c7bb33ffd03ef23c617" | ||
integrity sha512-fD4dn9cJX62QSP2TMFLXCOQOa+Bu2o7kWDjrU/FNLkNqPPcCKBLxCH/Lc+gNCRBKdEUGyI3arjAw7j0Yz1hnvw== | ||
dependencies: | ||
tslib "^1.9.3" | ||
|
||
"@webassemblyjs/[email protected]": | ||
version "1.4.3" | ||
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.3.tgz#3b3f6fced944d8660273347533e6d4d315b5934a" | ||
|
@@ -4491,9 +4498,10 @@ flatten@^1.0.2: | |
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782" | ||
|
||
flow-bin@^0.66.0: | ||
version "0.66.0" | ||
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.66.0.tgz#a96dde7015dc3343fd552a7b4963c02be705ca26" | ||
flow-bin@^0.111.0: | ||
version "0.111.3" | ||
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.111.3.tgz#8653a413400ebc966097a47c81fb4e6b722a5921" | ||
integrity sha512-Gn27aRTjSFicukZ/pq3raRERmSk9UWszhIK9eNtj6843L54YtK+jk2OkQWV70+VKi9LmWyfItCkhwoIVy7L2lA== | ||
|
||
flow-remove-types-no-whitespace@^1.0.3: | ||
version "1.0.5" | ||
|
@@ -9600,6 +9608,11 @@ trough@^1.0.0: | |
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.1.tgz#a9fd8b0394b0ae8fff82e0633a0a36ccad5b5f86" | ||
|
||
tslib@^1.9.3: | ||
version "1.10.0" | ||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" | ||
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== | ||
|
||
[email protected]: | ||
version "0.0.0" | ||
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Probably not a great idea. We should not keep such files in the repo.
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.
Hmmm... I'm not a VSCode user. I can go download VSCode and try to setup our repo with it, but from googling, it seems like this file is needed for flow https://code.visualstudio.com/docs/languages/javascript#_can-i-use-other-javascript-tools-like-flow
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.
I had to configure this myself too when setting up the local env yesterday. Not sure if committing it here is the best approach (I've done so in my projects), but it's gonna be needed for every VSC user.