Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 774acd6

Browse files
authored
feat: Split props out into a separate field (#35)
Having it pass along everything leads to svelte complaining about unexpected props unless you define `export let component;` in every svelte3 component, which... no. BREAKING CHANGE: Props for the svelte3 component must now be passed to the wrapped as `props` instead of the entire state of the wrapper being passed along. This prevents warnings from svelte3 components and is generally cleaner overall.
1 parent ea59102 commit 774acd6

File tree

5 files changed

+56
-49
lines changed

5 files changed

+56
-49
lines changed

3in2/component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
// svelte3 component to invoke
77
component : false,
88

9-
// All values are passed to the svelte3 component as props!
9+
// props for the component
10+
props : {},
1011
}),
1112

1213
methods : {
1314
instantiate() {
14-
const props = this.get();
15-
const { component } = props;
15+
const { component, props } = this.get();
1616
const { anchor } = this.refs;
1717

1818
// Cleanup any previous component instance first
@@ -56,7 +56,7 @@
5656
}
5757

5858
if(this.instance) {
59-
return this.instance.$set(current);
59+
return this.instance.$set(current.props);
6060
}
6161
});
6262
},

3in2/tests/component.test.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("3in2 component wrapper", () => {
2929
expect(() => new Wrapper({
3030
target : root,
3131
data : {
32-
component : true
32+
component : true,
3333
},
3434
})).toThrowErrorMatchingSnapshot();
3535
});
@@ -55,7 +55,9 @@ describe("3in2 component wrapper", () => {
5555
data : {
5656
component : ComponentA,
5757

58-
a : "A",
58+
props : {
59+
a : "A",
60+
},
5961
},
6062
});
6163

@@ -69,14 +71,18 @@ describe("3in2 component wrapper", () => {
6971
data : {
7072
component : ComponentA,
7173

72-
a : "A",
74+
props : {
75+
a : "A",
76+
},
7377
},
7478
});
7579

7680
expect(root.innerHTML).toMatchSnapshot();
7781

7882
wrapper.set({
79-
a : "A2",
83+
props : {
84+
a : "A2",
85+
},
8086
});
8187

8288
await wait();
@@ -91,15 +97,20 @@ describe("3in2 component wrapper", () => {
9197
data : {
9298
component : ComponentA,
9399

94-
a : "A",
100+
props : {
101+
a : "A",
102+
},
95103
},
96104
});
97105

98106
const child = wrapper.instance;
99107

100108
wrapper.set({
101109
component : ComponentA,
102-
a : "A2",
110+
111+
props : {
112+
a : "A2",
113+
},
103114
});
104115

105116
await wait();
@@ -114,7 +125,9 @@ describe("3in2 component wrapper", () => {
114125
data : {
115126
component : ComponentA,
116127

117-
a : "A",
128+
props : {
129+
a : "A",
130+
},
118131
},
119132
});
120133

@@ -156,7 +169,7 @@ describe("3in2 component wrapper", () => {
156169
class : "class",
157170
style : "color: red;",
158171
"data-foo" : "data-foo",
159-
}
172+
},
160173
},
161174
});
162175

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ $> npm install svelte@latest
4040
Wrap up a v3 component so it can be included within a svelte2 component.
4141

4242
```html
43-
<Wrapper {...props} />
43+
<Wrapper {component} {props} />
4444

4545
<script>
46-
import Component from "your-svelte3-component.svelte";
46+
import Component from "./svelte3-component.svelte";
4747
4848
export default {
4949
components : {
@@ -52,20 +52,17 @@ export default {
5252
5353
data : () => ({
5454
component : Component,
55+
props : {
56+
// any props for the component
57+
}
5558
}),
56-
57-
// This computed is here so that this component can essentially be invisible, it
58-
// exists solvely to help the transition and can be removed once v2 is gone
59-
computed : {
60-
props : (state) => state,
61-
},
6259
};
6360
```
6461
6562
| Data | Usage |
6663
| --- | --- |
6764
| `component` | The v3 component to wrap |
68-
| `...` | All other props on the component are passed directly to the v3 component |
65+
| `props` | Properties to set on the v3 component |
6966
7067
#### Stores
7168

package-lock.json

Lines changed: 17 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@
2222
"author": "Pat Cavit <npm@patcavit.com>",
2323
"license": "MIT",
2424
"dependencies": {
25-
"rollup-pluginutils": "^2.7.0"
25+
"rollup-pluginutils": "^2.8.1"
2626
},
2727
"devDependencies": {
2828
"@babel/plugin-transform-modules-commonjs": "^7.4.4",
29-
"@tivac/eslint-config": "^2.3.1",
29+
"@tivac/eslint-config": "^2.4.0",
3030
"babel-core": "^6.26.3",
31-
"babel-eslint": "^10.0.1",
31+
"babel-eslint": "^10.0.2",
3232
"babel-jest": "^24.8.0",
3333
"babel-plugin-add-module-exports": "^1.0.2",
3434
"conventional-changelog-cli": "^2.0.21",
35-
"eslint": "^6.0.0",
36-
"eslint-plugin-jest": "^22.5.1",
35+
"eslint": "^6.0.1",
36+
"eslint-plugin-jest": "^22.7.1",
3737
"jest": "^24.8.0",
3838
"jest-serializer-html": "^6.0.0",
3939
"p-immediate": "^3.1.0",
4040
"require-from-string": "^2.0.2",
41-
"rollup": "^1.12.1",
41+
"rollup": "^1.16.2",
4242
"rollup-plugin-hypothetical": "^2.1.0",
43-
"rollup-plugin-node-resolve": "^5.0.0",
43+
"rollup-plugin-node-resolve": "^5.1.0",
4444
"snapshot-diff": "^0.5.1",
45-
"svelte": "^3.4.1",
45+
"svelte": "^3.6.1",
4646
"svelte2": "npm:svelte@^2"
4747
},
4848
"peerDependencies": {

0 commit comments

Comments
 (0)