@wrnrlr/prelude 0.2.10 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/cd.yml +32 -0
- package/.github/workflows/ci.yml +31 -0
- package/LICENSE +21 -1
- package/deno.jsonc +5 -2
- package/package.json +1 -1
- package/src/canvas.js +16 -0
- package/src/domdiff.ts +92 -0
- package/src/form.js +20 -0
- package/src/hyperscript.ts +5 -2
- package/src/{controlflow.ts → list.ts} +2 -24
- package/src/mod.ts +11 -11
- package/src/osm.js +0 -0
- package/src/reactive.ts +49 -0
- package/src/resource.js +27 -4
- package/src/router.js +26 -7
- package/src/runtime.ts +244 -309
- package/src/select.js +1 -0
- package/src/show.ts +48 -0
- package/src/svg.js +0 -0
- package/src/switch.ts +96 -0
- package/src/table.js +0 -0
- package/test/hyperscript.js +9 -6
- package/test/list.js +4 -4
- package/test/types.ts +8 -4
- package/.github/workflows/publish.yml +0 -67
@@ -0,0 +1,32 @@
|
|
1
|
+
name: CD
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- release
|
7
|
+
|
8
|
+
permissions:
|
9
|
+
contents: read
|
10
|
+
id-token: write
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v4
|
17
|
+
- uses: denoland/setup-deno@v2
|
18
|
+
with:
|
19
|
+
deno-version: v2.x
|
20
|
+
- run: deno install
|
21
|
+
# - name: Lint
|
22
|
+
# run: deno lint
|
23
|
+
- run: deno task test
|
24
|
+
publish-jsr:
|
25
|
+
needs: test
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v4
|
29
|
+
- uses: denoland/setup-deno@v2
|
30
|
+
with:
|
31
|
+
deno-version: v2.x
|
32
|
+
- run: deno publish --allow-slow-types --allow-dirty
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v4
|
13
|
+
- uses: denoland/setup-deno@v2
|
14
|
+
with:
|
15
|
+
deno-version: v2.x
|
16
|
+
- run: deno install
|
17
|
+
# - run: deno lint
|
18
|
+
- run: deno task test --no-check
|
19
|
+
|
20
|
+
# Moving artifacts, website and docs into their own project...
|
21
|
+
# - name: Setup Pages
|
22
|
+
# uses: actions/configure-pages@v5
|
23
|
+
|
24
|
+
# - name: Upload artifact
|
25
|
+
# uses: actions/upload-pages-artifact@v3
|
26
|
+
# with:
|
27
|
+
# path: './www/dist'
|
28
|
+
|
29
|
+
# - name: Deploy to GitHub Pages
|
30
|
+
# id: deployment
|
31
|
+
# uses: actions/deploy-pages@v4
|
package/LICENSE
CHANGED
@@ -1 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Werner Laurensse
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/deno.jsonc
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wrnrlr/prelude",
|
3
|
-
"version": "0.2.
|
4
|
-
"exports":
|
3
|
+
"version": "0.2.15",
|
4
|
+
"exports": {
|
5
|
+
".": "./src/mod.ts",
|
6
|
+
"./style.css": "./src/style.css"
|
7
|
+
},
|
5
8
|
"compilerOptions": {
|
6
9
|
"strict": true,
|
7
10
|
"lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns"]
|
package/package.json
CHANGED
package/src/canvas.js
ADDED
package/src/domdiff.ts
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
// Original version: https://github.com/WebReflection/udomdiff/blob/master/index.js
|
2
|
+
/*
|
3
|
+
ISC License
|
4
|
+
|
5
|
+
Copyright (c) 2020, Andrea Giammarchi, @WebReflection
|
6
|
+
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
8
|
+
purpose with or without fee is hereby granted, provided that the above
|
9
|
+
copyright notice and this permission notice appear in all copies.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
16
|
+
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
18
|
+
*/
|
19
|
+
|
20
|
+
export function reconcileArrays(parentNode:Node, a:Element[], b:Element[]) {
|
21
|
+
const bLength = b.length
|
22
|
+
let aEnd = a.length,
|
23
|
+
bEnd = bLength,
|
24
|
+
aStart = 0,
|
25
|
+
bStart = 0,
|
26
|
+
map:Map<Node,number>|null = null;
|
27
|
+
const after = a[aEnd - 1].nextSibling
|
28
|
+
|
29
|
+
while (aStart < aEnd || bStart < bEnd) {
|
30
|
+
// common prefix
|
31
|
+
if (a[aStart] === b[bStart]) {
|
32
|
+
aStart++;
|
33
|
+
bStart++;
|
34
|
+
continue;
|
35
|
+
}
|
36
|
+
// common suffix
|
37
|
+
while (a[aEnd - 1] === b[bEnd - 1]) {
|
38
|
+
aEnd--;
|
39
|
+
bEnd--;
|
40
|
+
}
|
41
|
+
// append
|
42
|
+
if (aEnd === aStart) {
|
43
|
+
const node =
|
44
|
+
bEnd < bLength
|
45
|
+
? bStart
|
46
|
+
? b[bStart - 1].nextSibling
|
47
|
+
: b[bEnd - bStart]
|
48
|
+
: after;
|
49
|
+
|
50
|
+
while (bStart < bEnd) parentNode.insertBefore(b[bStart++], node);
|
51
|
+
// remove
|
52
|
+
} else if (bEnd === bStart) {
|
53
|
+
while (aStart < aEnd) {
|
54
|
+
if (!map || !map.has(a[aStart])) a[aStart].remove();
|
55
|
+
aStart++;
|
56
|
+
}
|
57
|
+
// swap backward
|
58
|
+
} else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
|
59
|
+
const node = a[--aEnd].nextSibling;
|
60
|
+
parentNode.insertBefore(b[bStart++], a[aStart++].nextSibling);
|
61
|
+
parentNode.insertBefore(b[--bEnd], node);
|
62
|
+
|
63
|
+
a[aEnd] = b[bEnd];
|
64
|
+
// fallback to map
|
65
|
+
} else {
|
66
|
+
if (!map) {
|
67
|
+
map = new Map();
|
68
|
+
let i = bStart;
|
69
|
+
while (i < bEnd) map.set(b[i], i++);
|
70
|
+
}
|
71
|
+
|
72
|
+
const index = map.get(a[aStart]);
|
73
|
+
if (index != null) {
|
74
|
+
if (bStart < index && index < bEnd) {
|
75
|
+
let i = aStart,
|
76
|
+
sequence = 1,
|
77
|
+
t:number|undefined;
|
78
|
+
|
79
|
+
while (++i < aEnd && i < bEnd) {
|
80
|
+
if ((t = map.get(a[i])) == null || t !== index + sequence) break;
|
81
|
+
sequence++;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (sequence > index - bStart) {
|
85
|
+
const node = a[aStart];
|
86
|
+
while (bStart < index) parentNode.insertBefore(b[bStart++], node);
|
87
|
+
} else parentNode.replaceChild(b[bStart++], a[aStart++]);
|
88
|
+
} else aStart++;
|
89
|
+
} else a[aStart++].remove();
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
package/src/form.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
import {signal, context, useContext} from './reactive.ts'
|
2
|
+
|
3
|
+
const Ctx = context()
|
4
|
+
const useForm = () => useContext(Ctx)
|
5
|
+
|
6
|
+
function Form(props) {
|
7
|
+
return h('form', h(Ctx.Provider, {value:[props.value]}, props.children))
|
8
|
+
}
|
9
|
+
|
10
|
+
function Input(props) {
|
11
|
+
if (props.name) {
|
12
|
+
const [form] = useForm()
|
13
|
+
props.value = wrap(form, props.name)
|
14
|
+
}
|
15
|
+
return h('input', props)
|
16
|
+
}
|
17
|
+
|
18
|
+
function CurrencyInput(props) {
|
19
|
+
return h(Input, props)
|
20
|
+
}
|
package/src/hyperscript.ts
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
import type {DOMElements} from './constants.ts'
|
2
|
-
import type {Runtime} from './runtime.ts'
|
2
|
+
import type {Runtime,Mountable} from './runtime.ts'
|
3
|
+
import {r} from './runtime.ts'
|
3
4
|
|
4
5
|
const ELEMENT: unique symbol = Symbol(), {isArray} = Array
|
5
6
|
|
6
|
-
export type Mountable = View | HTMLElement | string | number | bigint | symbol | boolean | Date | Mountable[];
|
7
|
+
// export type Mountable = View | HTMLElement | string | number | bigint | symbol | boolean | Date | Mountable[];
|
7
8
|
export type Component<T> = ((props:T) => Mountable) | ((props:T) => Mountable[])
|
8
9
|
export type Tag = typeof DOMElements extends Set<infer K> ? K : never;
|
9
10
|
export type Child = { ():Child } | Element | Child[] | string | number | symbol | bigint | boolean | Date | Record<string,unknown> | {():Child, [ELEMENT]:boolean}
|
10
11
|
export type View = {():void, [ELEMENT]?:boolean}
|
11
12
|
|
13
|
+
export const h = hyperscript(r)
|
14
|
+
|
12
15
|
// export type PropsKeys = typeof Properties extends Set<infer K> ? K : never;
|
13
16
|
// export type BooleanProps = typeof BooleanAttributes ext ends Set<infer K> ? K : never;
|
14
17
|
// export type HandlerProps = typeof DelegatedEvents extends Set<infer K> ? K : never;
|
@@ -1,28 +1,6 @@
|
|
1
1
|
// @ts-nocheck:
|
2
|
-
import
|
3
|
-
import
|
4
|
-
|
5
|
-
export type ShowProps<T> = {
|
6
|
-
when: T,
|
7
|
-
children: Child | ((a:()=>T)=>void),
|
8
|
-
fallback: unknown
|
9
|
-
}
|
10
|
-
|
11
|
-
/**
|
12
|
-
Show children if `when` prop is true, otherwise show `fallback`.
|
13
|
-
@group Components
|
14
|
-
*/
|
15
|
-
export function Show<T>(props:ShowProps) {
|
16
|
-
const condition = memo(()=>props.when)
|
17
|
-
return memo(()=>{
|
18
|
-
const c = condition()
|
19
|
-
if (c) {
|
20
|
-
const child = props.children
|
21
|
-
const fn = typeof child === "function" && child.length > 0
|
22
|
-
return fn ? untrack(() => child(() => props.when)) : child
|
23
|
-
} else return props.fallback
|
24
|
-
})
|
25
|
-
}
|
2
|
+
import { signal, untrack, batch, memo, root, onCleanup} from './reactive.ts'
|
3
|
+
import type { Signal, Setter, Mountable } from './reactive.ts'
|
26
4
|
|
27
5
|
export type ListProps<T, U extends Mountable, F = Getter | Signal> = {
|
28
6
|
each: F<T[]>,
|
package/src/mod.ts
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
export type {Getter,Setter,
|
2
|
-
export {signal,effect,untrack,batch,memo,root,wrap,fuse,onMount,onCleanup} from './reactive.ts'
|
1
|
+
export type {Getter,Setter,Signal} from './reactive.ts'
|
2
|
+
export {signal,effect,untrack,batch,memo,root,context,useContext,wrap,fuse,onMount,onCleanup} from './reactive.ts'
|
3
3
|
export {nbsp} from './constants.ts'
|
4
|
-
export {
|
5
|
-
export {
|
6
|
-
|
7
|
-
export
|
8
|
-
|
9
|
-
export {
|
4
|
+
export {List} from './list.ts'
|
5
|
+
export {Show} from './show.ts'
|
6
|
+
export {r, type Runtime} from './runtime.ts'
|
7
|
+
export type * from './hyperscript.ts'
|
8
|
+
export {hyperscript, h} from './hyperscript.ts'
|
9
|
+
export {HashRouter} from './router.js'
|
10
10
|
export {resource,makeAbortable,abortable} from './resource.js'
|
11
11
|
|
12
|
-
const r:Runtime = /*#__PURE__*/ (typeof window === 'object') ? runtime(window) : undefined as unknown as Runtime
|
12
|
+
// const r:Runtime = /*#__PURE__*/ (typeof window === 'object') ? runtime(window) : undefined as unknown as Runtime
|
13
13
|
|
14
14
|
/** h
|
15
15
|
@example Element with a single child
|
@@ -26,7 +26,7 @@ h(Input,{onInput:e => {}})
|
|
26
26
|
```
|
27
27
|
@group Hyperscript
|
28
28
|
*/
|
29
|
-
export const h: HyperScript = /*#__PURE__*/ hyperscript(r, parseHtmlTag)
|
29
|
+
// export const h: HyperScript = /*#__PURE__*/ hyperscript(r, parseHtmlTag)
|
30
30
|
|
31
31
|
/** render
|
32
32
|
|
@@ -36,4 +36,4 @@ Render component to DOM element.
|
|
36
36
|
render(()=>'hi', document.body)
|
37
37
|
```
|
38
38
|
*/
|
39
|
-
export const render:(code:()=>void, element:Element, init:unknown) => void = /*#__PURE__*/ r?.render
|
39
|
+
// export const render:(code:()=>void, element:Element, init:unknown) => void = /*#__PURE__*/ r?.render
|
package/src/osm.js
ADDED
File without changes
|
package/src/reactive.ts
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
Inspired by S.js by Adam Haile, https://github.com/solidjs/solid
|
3
|
+
|
4
|
+
The MIT License (MIT)
|
5
|
+
|
6
|
+
Copyright (c) 2017 Adam Haile
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
10
|
+
in the Software without restriction, including without limitation the rights
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
13
|
+
furnished to do so, subject to the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
16
|
+
copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
24
|
+
SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
1
27
|
// @ts-nocheck:
|
2
28
|
export interface EffectOptions {
|
3
29
|
name?: string;
|
@@ -399,6 +425,29 @@ export function untrack<T>(fn: ()=>T):T {
|
|
399
425
|
return observe(fn, OBSERVER, false)!
|
400
426
|
}
|
401
427
|
|
428
|
+
function resolveChildren(children: any | Getter<any>): any {
|
429
|
+
if (typeof children === "function" && !children.length) return resolveChildren(children());
|
430
|
+
if (Array.isArray(children)) {
|
431
|
+
const results: any[] = [];
|
432
|
+
for (let i = 0; i < children.length; i++) {
|
433
|
+
const result = resolveChildren(children[i]);
|
434
|
+
Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
|
435
|
+
}
|
436
|
+
return results;
|
437
|
+
}
|
438
|
+
return children as ResolvedChildren;
|
439
|
+
}
|
440
|
+
|
441
|
+
export function children(fn: Getter<any>): any {
|
442
|
+
const children = memo(fn);
|
443
|
+
const kids = memo(() => resolveChildren(children()));
|
444
|
+
(kids as any).toArray = () => {
|
445
|
+
const c = kids();
|
446
|
+
return Array.isArray(c) ? c : c != null ? [c] : [];
|
447
|
+
};
|
448
|
+
return kids as any;
|
449
|
+
}
|
450
|
+
|
402
451
|
function observe<T>(fn: Fn<T>, observer: Observer | undefined, tracking: boolean ): T|undefined {
|
403
452
|
const OBSERVER_PREV = OBSERVER;
|
404
453
|
const TRACKING_PREV = TRACKING;
|
package/src/resource.js
CHANGED
@@ -1,10 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Copyright (c) 2016-2025 Ryan Carniato
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
23
|
+
*/
|
1
24
|
// @ts-nocheck:
|
2
25
|
import {signal,effect,untrack,memo,batch,onCleanup} from './reactive.ts'
|
3
26
|
|
4
27
|
const NO_INIT = {}
|
5
28
|
|
6
29
|
/**
|
7
|
-
resource
|
30
|
+
`resource`
|
8
31
|
*/
|
9
32
|
export function resource(pSource,pFetcher,pOptions) {
|
10
33
|
let source
|
@@ -53,9 +76,9 @@ export function resource(pSource,pFetcher,pOptions) {
|
|
53
76
|
}, false)
|
54
77
|
}
|
55
78
|
|
56
|
-
function read() {
|
57
|
-
const v = value()
|
58
|
-
|
79
|
+
function read(...a) {
|
80
|
+
const v = a.length===0 ? value() : value(a[0])
|
81
|
+
const err = error();
|
59
82
|
if (err !== undefined && !pr) throw err;
|
60
83
|
return v;
|
61
84
|
}
|
package/src/router.js
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Copyright (c) 2016-2025 Ryan Carniato
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
23
|
+
*/
|
1
24
|
// @ts-nocheck
|
2
25
|
import {signal,effect,batch,untrack,memo,wrap,context,useContext,onMount} from './reactive.ts'
|
3
26
|
// import {h} from './hyperscript.ts'
|
@@ -8,7 +31,7 @@ export const useNavigate = () => wrap(useRouter(),'navigate')
|
|
8
31
|
export const useParams = () => wrap(useRouter(),'params')
|
9
32
|
export const useSearch = () => wrap(useRouter(),'search')
|
10
33
|
|
11
|
-
export function
|
34
|
+
export function HashRouter(props) {
|
12
35
|
const routes = props.children
|
13
36
|
const NotFound = ()=>'Not found'
|
14
37
|
const render = () => {console.log('render')}
|
@@ -18,13 +41,9 @@ export function Router(props) {
|
|
18
41
|
const search = signal(null)
|
19
42
|
onMount(()=>{
|
20
43
|
window.addEventListener("popstate", (event) => {
|
21
|
-
batch(()=>
|
22
|
-
const hash = parseHash(document.location.hash)
|
23
|
-
navigate(hash)
|
24
|
-
})
|
44
|
+
batch(()=>navigate(parseHash(document.location.hash)))
|
25
45
|
})
|
26
|
-
|
27
|
-
navigate(hash)
|
46
|
+
navigate(parseHash(document.location.hash))
|
28
47
|
})
|
29
48
|
const children = memo(() => {
|
30
49
|
let location = navigate()
|