Skip to content

Commit a05b499

Browse files
authored
Merge pull request #1354 from Incognitus-Io/dev
Add provided/inject support for Composition API components
2 parents 1888864 + 9552017 commit a05b499

File tree

6 files changed

+79
-3
lines changed

6 files changed

+79
-3
lines changed

Diff for: .vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"javascript.validate.enable": false,
3+
"flow.pathToFlow": "${workspaceFolder}/node_modules/.bin/flow"
4+
}

Diff for: package.json

+3
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,8 @@
8888
"vuex": "^3.0.1",
8989
"webpack": "^3.0.1",
9090
"webpack-node-externals": "^1.6.0"
91+
},
92+
"devDependencies": {
93+
"@vue/composition-api": "^0.3.2"
9194
}
9295
}

Diff for: packages/create-instance/create-instance.js

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export default function createInstance(
8282
const parentComponentOptions = options.parentComponent || {}
8383

8484
parentComponentOptions.provide = options.provide
85+
parentComponentOptions._provided = options.provide
8586
parentComponentOptions.$_doNotStubChildren = true
8687
parentComponentOptions._isFunctionalContainer = componentOptions.functional
8788
parentComponentOptions.render = function(h) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div>{{ fromMount }}</div>
3+
</template>
4+
5+
<script>
6+
import { createComponent, inject, ref } from '@vue/composition-api'
7+
8+
export default createComponent({
9+
name: 'component-with-inject-composition',
10+
setup: () => {
11+
const fromMount = inject('fromMount')
12+
const setInSetup = ref('created')
13+
14+
return {
15+
fromMount,
16+
setInSetup
17+
}
18+
}
19+
})
20+
</script>

Diff for: test/specs/mounting-options/provide.spec.js

+35
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { config } from '~vue/test-utils'
2+
import { createLocalVue } from '~vue/test-utils'
23
import ComponentWithInject from '~resources/components/component-with-inject.vue'
4+
import CompositionComponentWithInject from '~resources/components/component-with-inject-composition.vue'
35
import { injectSupported } from '~resources/utils'
46
import { describeWithShallowAndMount } from '~resources/utils'
57
import { itDoNotRunIf, itSkipIf } from 'conditional-specs'
8+
import VueCompositionApi from '@vue/composition-api'
69

710
describeWithShallowAndMount('options.provide', mountingMethod => {
811
let configProvideSave
@@ -58,6 +61,23 @@ describeWithShallowAndMount('options.provide', mountingMethod => {
5861
}
5962
)
6063

64+
itDoNotRunIf(
65+
!injectSupported || mountingMethod.name === 'renderToString',
66+
'supports setup in composition api component',
67+
() => {
68+
if (!injectSupported) return
69+
70+
const localVue = createLocalVue()
71+
localVue.use(VueCompositionApi)
72+
const wrapper = mountingMethod(CompositionComponentWithInject, {
73+
provide: { fromMount: '_' },
74+
localVue
75+
})
76+
77+
expect(wrapper.vm.setInSetup).to.equal('created')
78+
}
79+
)
80+
6181
itSkipIf(
6282
mountingMethod.name === 'renderToString',
6383
'injects the provide from the config',
@@ -86,6 +106,21 @@ describeWithShallowAndMount('options.provide', mountingMethod => {
86106
}
87107
)
88108

109+
itDoNotRunIf(
110+
!injectSupported,
111+
'injects in a composition api component',
112+
() => {
113+
const localVue = createLocalVue()
114+
localVue.use(VueCompositionApi)
115+
const wrapper = mountingMethod(CompositionComponentWithInject, {
116+
provide: { fromMount: '_' },
117+
localVue
118+
})
119+
120+
expect(wrapper.html()).to.contain('_')
121+
}
122+
)
123+
89124
it('config with function throws', () => {
90125
config.provide = () => {}
91126

Diff for: yarn.lock

+16-3
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,13 @@
810810
source-map "^0.5.6"
811811
vue-template-es2015-compiler "^1.6.0"
812812

813+
"@vue/composition-api@^0.3.2":
814+
version "0.3.2"
815+
resolved "https://registry.yarnpkg.com/@vue/composition-api/-/composition-api-0.3.2.tgz#2d797028e489bf7812f08c7bb33ffd03ef23c617"
816+
integrity sha512-fD4dn9cJX62QSP2TMFLXCOQOa+Bu2o7kWDjrU/FNLkNqPPcCKBLxCH/Lc+gNCRBKdEUGyI3arjAw7j0Yz1hnvw==
817+
dependencies:
818+
tslib "^1.9.3"
819+
813820
"@webassemblyjs/[email protected]":
814821
version "1.4.3"
815822
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.4.3.tgz#3b3f6fced944d8660273347533e6d4d315b5934a"
@@ -4491,9 +4498,10 @@ flatten@^1.0.2:
44914498
version "1.0.2"
44924499
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
44934500

4494-
flow-bin@^0.66.0:
4495-
version "0.66.0"
4496-
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.66.0.tgz#a96dde7015dc3343fd552a7b4963c02be705ca26"
4501+
flow-bin@^0.111.0:
4502+
version "0.111.3"
4503+
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.111.3.tgz#8653a413400ebc966097a47c81fb4e6b722a5921"
4504+
integrity sha512-Gn27aRTjSFicukZ/pq3raRERmSk9UWszhIK9eNtj6843L54YtK+jk2OkQWV70+VKi9LmWyfItCkhwoIVy7L2lA==
44974505

44984506
flow-remove-types-no-whitespace@^1.0.3:
44994507
version "1.0.5"
@@ -9600,6 +9608,11 @@ trough@^1.0.0:
96009608
version "1.0.1"
96019609
resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.1.tgz#a9fd8b0394b0ae8fff82e0633a0a36ccad5b5f86"
96029610

9611+
tslib@^1.9.3:
9612+
version "1.10.0"
9613+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
9614+
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==
9615+
96039616
96049617
version "0.0.0"
96059618
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"

0 commit comments

Comments
 (0)