File tree Expand file tree Collapse file tree 6 files changed +74
-1
lines changed
Expand file tree Collapse file tree 6 files changed +74
-1
lines changed Original file line number Diff line number Diff line change 11# Architecture
22
3- This document describes design desicions and implementation details of the preprocessor.
3+ This document describes designdecisions and implementation details of the preprocessor.
4+
5+ ** Principles:**
6+
7+ - Compatibility first, Ease-of-use second and Performance last.
48
59## Context
610
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import used from " ./used" ;
3+
4+ export let use: () => any ;
5+ export let out: any = undefined ;
6+
7+ let ready = false ;
8+
9+ function setValue(value : any ) {
10+ out = value ;
11+ ready = true ;
12+ }
13+
14+ function Hook<T >(props : { use: () => T ; setValue(val : T ): void }) {
15+ const value = props .use ();
16+ props .setValue (value );
17+ return null ;
18+ }
19+ used (Hook );
20+ </script >
21+
22+ <react:Hook {use } {setValue } />
23+ {#if ready }
24+ <slot {out } />
25+ {/if }
Original file line number Diff line number Diff line change 11export { default as useStore } from "./useStore.js" ;
22export { default as reactify } from "./reactify.js" ;
33export { default as sveltify } from "./sveltify.js" ;
4+ export { default as Hook } from "./Hook.svelte" ;
Original file line number Diff line number Diff line change 1+ /* eslint-disable @typescript-eslint/no-unused-vars */
2+
3+ /**
4+ * Svelte/TypeScript is not (yet) able to detect usage of the <react:ComponentX> syntax.
5+ * This causes `X is declared but its value is never read. (ts:6133)` errors.
6+ *
7+ * This function can be used to suppress these errors.
8+ *
9+ * Usage:
10+ *
11+ * used(ComponentX, ComponentY);
12+ */
13+ export default function used ( ...args : any [ ] ) { }
Original file line number Diff line number Diff line change 88
99 <li ><a href =" /context-svelte" >getContext()</a ></li >
1010 <li ><a href =" /context-react" >useContext()</a ></li >
11+
12+ <li ><a href =" /hooks" >Using hooks</a ></li >
1113</ul >
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import { Hook } from " $lib" ;
3+ import { useState } from " react" ;
4+
5+ function useSomeState() {
6+ return useState (" Initial value" );
7+ }
8+
9+ function useMultipleHooks() {
10+ const [x] = useState (1 );
11+ const [y] = useState (2 );
12+ return { x , y };
13+ }
14+ </script >
15+
16+ <Hook use ={useSomeState } let:out ={[value , setValue ]}>
17+ <div >{value }</div >
18+ <button
19+ on:click ={() => {
20+ setValue (" Changed" );
21+ }}>Change</button
22+ >
23+ </Hook >
24+ <hr />
25+ <Hook use ={useMultipleHooks } let:out ={position }>
26+ x: {position .x }
27+ y: {position .y }
28+ </Hook >
You can’t perform that action at this time.
0 commit comments