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

Commit 43e380b

Browse files
committed
feat: first pass at some basic functionality
1 parent 069c9c3 commit 43e380b

File tree

5 files changed

+1103
-0
lines changed

5 files changed

+1103
-0
lines changed

3in2/component.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<div {...attrs} ref:root>
2+
<svelte:component this="{Component}" />
3+
</div>
4+
5+
<script>
6+
export default {
7+
data : () => ({
8+
// svelte3 component to invoke
9+
component : false,
10+
11+
// props for svelte3 component
12+
props : false,
13+
14+
// Attributes to apply to the placeholder <div> this component has to create
15+
attrs : false,
16+
}),
17+
18+
oncreate() {
19+
const { component, props } = this.get();
20+
21+
this.instance = new component({
22+
target : this.refs.root,
23+
props,
24+
});
25+
26+
this.on("state", ({ current }) => this.instance.$set(current.props));
27+
},
28+
29+
ondestroy() {
30+
this.instance.$destroy();
31+
},
32+
};
33+
</script>

3in2/store.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Store as Svelte2Store } from "svelte2/store.js";
2+
3+
export class Store extends Svelte2Store {
4+
constructor(store) {
5+
super();
6+
7+
this._store = store;
8+
this._set = this.set;
9+
10+
const unsubscribe = store.subscribe((value) => {
11+
// Objects are splatted
12+
if(typeof value === "object" && !Array.isArray(value)) {
13+
return this.set(value);
14+
}
15+
16+
// Everything else is set to the "value" property
17+
this._set({ value });
18+
});
19+
20+
this.unsubscribe = unsubscribe;
21+
22+
this.set = (args) => {
23+
if(!this._store.set) {
24+
throw new Error("Called .set() on a readable store");
25+
}
26+
27+
this._set(args);
28+
};
29+
}
30+
};

0 commit comments

Comments
 (0)