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

Commit 371a370

Browse files
committed
feat(3in2): pass props along transparently
BREAKING CHANGE: Previously props to be passed to the svelte3 component would be set in a `props` object, now they live alongside the special `component` and `attrs` properties. This facilitates easier porting of code since the wrapper component can be instantiated & have updated props passed to it exactly like the svelte2 component did previously.
1 parent 04932de commit 371a370

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

3in2/component.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
methods : {
1717
instantiate() {
18-
const { component, props } = this.get();
18+
const { component, attrs, ...props } = this.get();
1919
const { target } = this.refs;
2020

2121
// Cleanup any previous component instance first
@@ -34,6 +34,10 @@
3434
},
3535

3636
cleanup() {
37+
if(!this.instance) {
38+
return;
39+
}
40+
3741
this.instance.$destroy();
3842
this.instance = null;
3943
},
@@ -48,22 +52,19 @@
4852

4953
this.on("state", ({ changed, current }) => {
5054
if(changed.component) {
51-
this.instantiate();
52-
53-
return;
55+
return this.instantiate();
5456
}
5557

56-
if(changed.props && this.instance) {
57-
this.instance.$set(current.props)
58+
if(this.instance) {
59+
const { component, attrs, ...props } = current;
5860

59-
return;
61+
return this.instance.$set(props);
6062
}
6163
});
6264
},
6365

6466
ondestroy() {
65-
this.instance.$destroy();
66-
this.instance = null;
67+
this.cleanup();
6768
},
6869
};
6970
</script>

3in2/tests/component.test.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ describe("3in2 component wrapper", () => {
5555
data : {
5656
component : ComponentA,
5757

58-
props : {
59-
a : "A",
60-
},
58+
a : "A",
6159
},
6260
});
6361

@@ -71,18 +69,14 @@ describe("3in2 component wrapper", () => {
7169
data : {
7270
component : ComponentA,
7371

74-
props : {
75-
a : "A",
76-
},
72+
a : "A",
7773
},
7874
});
7975

8076
expect(root.innerHTML).toMatchSnapshot();
8177

8278
wrapper.set({
83-
props : {
84-
a : "A2",
85-
},
79+
a : "A2",
8680
});
8781

8882
await wait();
@@ -97,9 +91,7 @@ describe("3in2 component wrapper", () => {
9791
data : {
9892
component : ComponentA,
9993

100-
props : {
101-
a : "A",
102-
},
94+
a : "A",
10395
},
10496
});
10597

0 commit comments

Comments
 (0)