This repository was archived by the owner on Mar 1, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +1103
-0
lines changed
Expand file tree Collapse file tree 5 files changed +1103
-0
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments