Skip to content

Commit ac36b2a

Browse files
committed
Cleanup sandbox and walker
1 parent 71045e0 commit ac36b2a

File tree

4 files changed

+152
-168
lines changed

4 files changed

+152
-168
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"outin",
1111
"sarif",
1212
"stefanzweifel",
13+
"sweb",
1314
"taze",
1415
"todomvc",
1516
"twind",

examples/sandbox/src/App.tsx

Lines changed: 76 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,53 @@
1-
import {
2-
type Component,
3-
createComponent,
4-
createComputed,
5-
createEffect,
6-
createMemo,
7-
createRenderEffect,
8-
createResource,
9-
createRoot,
10-
createSignal,
11-
ErrorBoundary,
12-
type ParentComponent,
13-
type Setter,
14-
Show,
15-
Suspense,
16-
} from 'solid-js'
1+
import * as s from 'solid-js'
172
import {createMutable} from 'solid-js/store'
3+
import * as sweb from 'solid-js/web'
184
import Recursive from './Recursive.tsx'
195
import {ThemeExample} from './Theme.tsx'
20-
import Todos from './Todos.tsx'
6+
7+
// import Todos from './Todos.tsx'
8+
const Todos = s.lazy(() => import('./Todos.tsx'))
219

2210
const doMediumCalc = () => {
2311
Array.from({length: 1000000}, (_, i) => i).sort(() => Math.random() - 5)
2412
}
2513

26-
let setRootCount: Setter<number>
14+
let setRootCount: s.Setter<number>
2715
let disposeOuterRoot: VoidFunction
2816

29-
createRoot(dispose => {
17+
s.createRoot(dispose => {
3018
disposeOuterRoot = dispose
3119

32-
const [count, setCount] = createSignal(0)
20+
const [count, setCount] = s.createSignal(0)
3321
setRootCount = setCount
3422

3523
function createEffectInRoot(dispose: VoidFunction) {
36-
createEffect(() => count() === 4 && dispose(), undefined, {})
24+
s.createEffect(() => count() === 4 && dispose(), undefined, {})
3725

38-
createRoot(_ => {
39-
createEffect(() => count())
26+
s.createRoot(_ => {
27+
s.createEffect(() => count())
4028
})
4129
}
4230

43-
createEffect(() => {
31+
s.createEffect(() => {
4432
count()
4533
if (count() === 1) {
46-
createRoot(createEffectInRoot)
34+
s.createRoot(createEffectInRoot)
4735
}
4836
}, undefined)
4937
})
5038

5139
const Button = (props: {text: string; onClick: VoidFunction}) => {
52-
const text = createMemo(() => <span>{props.text}</span>)
40+
const text = s.createMemo(() => <span>{props.text}</span>)
5341
return (
5442
<button aria-label={props.text} onClick={props.onClick}>
5543
{text()}
5644
</button>
5745
)
5846
}
5947

60-
const PassChildren: ParentComponent = props => props.children
48+
const PassChildren: s.ParentComponent = props => props.children
6149

62-
const Article: Component = () => {
50+
const Article: s.Component = () => {
6351
const state = createMutable({
6452
count: 0,
6553
other: {name: 'article'},
@@ -70,7 +58,7 @@ const Article: Component = () => {
7058
})
7159
;(state as any).circular = state
7260

73-
const [data] = createResource(
61+
const [data] = s.createResource(
7462
() => state.count,
7563
async c => {
7664
await new Promise(r => setTimeout(r, 1000))
@@ -90,19 +78,19 @@ const Article: Component = () => {
9078
</b>
9179
</p>
9280
{/* <p>Count: {state.count}</p> */}
93-
<Suspense>
81+
<s.Suspense>
9482
<p>
9583
<PassChildren>
9684
<button onClick={() => state.count++}>Increment {data()}</button>
9785
</PassChildren>
9886
</p>
99-
</Suspense>
87+
</s.Suspense>
10088
</article>
10189
)
10290
}
10391

10492
const DynamicSpreadParent = () => {
105-
const [props, setProps] = createSignal<any>({
93+
const [props, setProps] = s.createSignal<any>({
10694
a: 1,
10795
b: 2,
10896
c: 3,
@@ -120,25 +108,25 @@ const DynamicSpreadParent = () => {
120108
return <DynamicSpreadChild {...props()} />
121109
}
122110

123-
const Broken: Component = () => {
111+
const Broken: s.Component = () => {
124112
throw new Error('Oh No')
125113
}
126114

127-
const App: Component = () => {
128-
const [count, setCount] = createSignal(0)
129-
const [showEven, setShowEven] = createSignal(false)
130-
const fnSig = createSignal({fn: () => {}}, {equals: (a, b) => a.fn === b.fn})
131-
const nullSig = createSignal(null)
132-
const symbolSig = createSignal(Symbol('hello-symbol'))
133-
const [header, setHeader] = createSignal(
115+
const App: s.Component = () => {
116+
const [count, setCount] = s.createSignal(0)
117+
const [showEven, setShowEven] = s.createSignal(false)
118+
const fnSig = s.createSignal({fn: () => {}}, {equals: (a, b) => a.fn === b.fn})
119+
const nullSig = s.createSignal(null)
120+
const symbolSig = s.createSignal(Symbol('hello-symbol'))
121+
const [header, setHeader] = s.createSignal(
134122
<h1 onClick={() => setHeader(<h1>Call that an easter egg</h1>)}>Welcome to the Sandbox</h1>,
135123
)
136124

137125
// setInterval(() => {
138126
// setCount(count() + 1)
139127
// }, 2000)
140128

141-
const objmemo = createMemo(() => {
129+
const objmemo = s.createMemo(() => {
142130
return {
143131
foo: 'bar',
144132
count: count(),
@@ -148,22 +136,18 @@ const App: Component = () => {
148136
}
149137
})
150138

151-
createComputed(
152-
_ => {
153-
const hello = createSignal('hello')
154-
setShowEven(count() % 3 === 0)
155-
return count()
156-
},
157-
undefined,
158-
{name: 'very-long-name-that-will-definitely-not-have-enough-space-to-render'},
159-
)
139+
s.createComputed(_ => {
140+
const hello = s.createSignal('hello')
141+
setShowEven(count() % 3 === 0)
142+
return count()
143+
}, undefined, {name: 'very-long-name-that-will-definitely-not-have-enough-space-to-render'})
160144

161-
createComputed(() => {}, undefined, {name: 'frozen'})
162-
createRenderEffect(() => {})
145+
s.createComputed(() => {}, undefined, {name: 'frozen'})
146+
s.createRenderEffect(() => {})
163147

164-
const Bold: ParentComponent = props => <b>{props.children}</b>
148+
const Bold: s.ParentComponent = props => <b>{props.children}</b>
165149

166-
const [showBroken, setShowBroken] = createSignal(false)
150+
const [showBroken, setShowBroken] = s.createSignal(false)
167151

168152
return (
169153
<>
@@ -174,58 +158,64 @@ const App: Component = () => {
174158
<Button onClick={() => setCount(p => ++p)} text={`Count: ${count()}`} />
175159
<Button onClick={() => setCount(p => ++p)} text={`Count: ${count()}`} />
176160
</header>
177-
<div style={{height: '1rem', 'margin-top': '1rem'}}>
178-
<Show when={showEven()}>
179-
{createComponent(() => {
180-
return <Bold>{count()} is even!</Bold>
181-
}, {})}
182-
</Show>
183-
</div>
161+
<sweb.Dynamic
162+
component='div'
163+
style={{height: '1rem', 'margin-top': '1rem'}}
164+
>
165+
<s.Show when={showEven()}>
166+
{s.createComponent(() => <>
167+
<Bold>{count()} is even!</Bold>
168+
</>, {})}
169+
</s.Show>
170+
</sweb.Dynamic>
184171
{/* <button onClick={() => disposeApp()}>Dispose whole application</button>
185172
<br /> */}
186173
<button onClick={() => setShowBroken(p => !p)}>
187174
{showBroken() ? 'Hide' : 'Show'} broken component.
188175
</button>
189-
<ErrorBoundary
190-
fallback={(err, reset) => (
191-
<>
192-
{err.toString()}
193-
<button
194-
onClick={() => {
195-
setShowBroken(false)
196-
reset()
197-
}}
198-
>
199-
Reset
200-
</button>
201-
</>
202-
)}
176+
<s.ErrorBoundary
177+
fallback={(err, reset) => <>
178+
{err.toString()}
179+
<button
180+
onClick={() => {
181+
setShowBroken(false)
182+
reset()
183+
}}
184+
>
185+
Reset
186+
</button>
187+
</>}
203188
>
204-
<Show when={showBroken()}>
189+
<s.Show when={showBroken()}>
205190
<Broken />
206-
</Show>
207-
</ErrorBoundary>
191+
</s.Show>
192+
</s.ErrorBoundary>
208193
<br />
209194
<br />
210195
</div>
211196
<DynamicSpreadParent />
212197
<button onClick={() => setRootCount(p => ++p)}>Update root count</button>
213198
<button onClick={() => disposeOuterRoot()}>Dispose OUTSIDE_ROOT</button>
214199
<Article />
215-
<Todos />
216-
<div style={{margin: '24px'}}>
217-
<CountingComponent />
218-
</div>
219-
<div style={{margin: '24px'}}>
220-
<ThemeExample />
221-
</div>
200+
<Todos title='Simple Todos Example' />
201+
{s.untrack(() => {
202+
const MARGIN = '24px'
203+
return <>
204+
<div style={{margin: MARGIN}}>
205+
<CountingComponent />
206+
</div>
207+
<div style={{margin: MARGIN}}>
208+
<ThemeExample />
209+
</div>
210+
</>
211+
})}
222212
<Recursive />
223213
</>
224214
)
225215
}
226216

227217
const CountingComponent = () => {
228-
const [count, setCount] = createSignal(0)
218+
const [count, setCount] = s.createSignal(0)
229219
// const interval = setInterval(() => setCount(c => c + 1), 1000)
230220
// onCleanup(() => clearInterval(interval))
231221
return <div>Count value is {count()}</div>

0 commit comments

Comments
 (0)