Skip to content

Commit 655e2ab

Browse files
committed
0.2.0-alpha.13
1 parent 3dc9878 commit 655e2ab

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

apps/vite/src/examples/counter-example.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@ import { computed, Lifecycle, ref, Signal, tags } from "@purifyjs/core";
33
const { div, section, button, ul, li, input } = tags;
44

55
function App() {
6-
return div().id("app").children(Counter());
6+
return div().id("app").replaceChildren$(Counter());
77
}
88

99
function Counter() {
1010
const count = ref(0);
1111
const double = count.derive((count) => count * 2);
1212
const half = computed(() => count.val * 0.5);
1313

14-
return div().children(
14+
return div().replaceChildren$(
1515
section({ class: "input" })
1616
.ariaLabel("Input")
17-
.children(
17+
.replaceChildren$(
1818
button()
1919
.title("Decrement by 1")
2020
.onclick(() => count.val--)
2121
.textContent("-"),
22-
input().type("number").effect(useBindNumber(count)).step("1"),
22+
input().type("number").$effect(useBindNumber(count)).step("1"),
2323
button()
2424
.title("Increment by 1")
2525
.onclick(() => count.val++)
2626
.textContent("+"),
2727
),
2828
section({ class: "output" })
2929
.ariaLabel("Output")
30-
.children(
31-
ul().children(
32-
li().children("Count: ", count),
33-
li().children("Double: ", double),
34-
li().children("Half: ", half),
30+
.replaceChildren$(
31+
ul().replaceChildren$(
32+
li().replaceChildren$("Count: ", count),
33+
li().replaceChildren$("Double: ", double),
34+
li().replaceChildren$("Half: ", half),
3535
),
3636
),
3737
);
@@ -54,4 +54,4 @@ function useBindNumber(
5454
};
5555
}
5656

57-
document.body.append(App().node);
57+
document.body.append(App().$node);

apps/vite/src/examples/shadowroot-example.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import { Builder, ref, tags } from "@purifyjs/core";
33
const { div, button } = tags;
44

55
function App() {
6-
return div().id("app").children(Counter());
6+
return div().id("app").replaceChildren$(Counter());
77
}
88

99
function Counter() {
1010
const host = div();
11-
const shadow = new Builder(host.node.attachShadow({ mode: "open" }));
11+
const shadow = new Builder(host.$node.attachShadow({ mode: "open" }));
1212

1313
const count = ref(0);
1414

15-
shadow.children(
15+
shadow.replaceChildren$(
1616
button()
1717
.title("Click me!")
1818
.onclick(() => count.val++)
19-
.children("Count:", count),
19+
.replaceChildren$("Count:", count),
2020
);
2121
return host;
2222
}
2323

24-
document.body.append(App().node);
24+
document.body.append(App().$node);

apps/vite/src/examples/web-component-example.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Builder, ref, tags, WithLifecycle } from "@purifyjs/core";
33
const { div, button } = tags;
44

55
function App() {
6-
return div().id("app").children(new CounterElement());
6+
return div().id("app").replaceChildren$(new CounterElement());
77
}
88

99
declare global {
@@ -21,13 +21,13 @@ class CounterElement extends WithLifecycle(HTMLElement) {
2121
super();
2222
const self = new Builder<CounterElement>(this);
2323

24-
self.children(
24+
self.replaceChildren$(
2525
button()
2626
.title("Click me!")
2727
.onclick(() => this.#count.val++)
28-
.children("Count:", this.#count),
28+
.replaceChildren$("Count:", this.#count),
2929
);
3030
}
3131
}
3232

33-
document.body.append(App().node);
33+
document.body.append(App().$node);

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@purifyjs/core",
3-
"version": "0.2.0-alpha.12",
3+
"version": "0.2.0-alpha.13",
44
"workspace": ["./apps/vite", "./apps/size"],
55
"exports": {
66
".": "./lib/mod.ts",

lib/tags.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ type IsProxyableProperty<T, K extends keyof T> = If<
7979
Not<Extends<K, keyof EventTarget>> & ((Not<IsReadonly<T, K>> & Not<IsFunction<T[K]>>) | (IsFunction<T[K]> & IsNullable<T[K]>))
8080
>;
8181

82+
type IsReflectFunction<T, K extends keyof T> = If<
83+
& IsFunction<T[K]>
84+
& Extends<K, keyof Lifecycle>
85+
>;
86+
8287
type IsProxyableFunction<T, K extends keyof T> = If<
8388
& Not<Extends<K, keyof EventTarget>>
8489
& (
@@ -119,7 +124,7 @@ type ProxyFunctionArgs<T extends Node, K extends keyof T, Args extends unknown[]
119124
: T extends WithLifecycle ? RecursiveSignalArgs<Args>
120125
: Args;
121126

122-
type MaybeNodeLikeArg<T> = T extends Node ? T | Builder<T> | null : T;
127+
type MaybeNodeLikeArg<T> = T extends Node ? T | Builder<T> | null : T extends string ? string | { toString(): string } : T;
123128
type MaybeNodeLikeArgs<Args extends unknown[], R extends unknown[] = []> = Args extends [infer Head, ...infer Tail]
124129
? MaybeNodeLikeArgs<Tail, [...R, MaybeNodeLikeArg<Head>]>
125130
: Args extends (infer U)[] ? MaybeNodeLikeArg<U>[]
@@ -134,6 +139,9 @@ type ProxyNodeFunctionArgs<
134139
: RecursiveArrayArgs<Args>;
135140

136141
export type Builder<T extends Node = Node> =
142+
& {
143+
[K in keyof T as If<IsReflectFunction<T, K>, K>]: T[K] extends (...args: infer Args) => any ? (...args: Args) => Builder<T> : never;
144+
}
137145
& {
138146
[K in keyof T as If<IsProxyableProperty<T, K>, K>]: (value: ProxyPropertyArg<T, K>) => Builder<T>;
139147
}
@@ -199,7 +207,7 @@ export let Builder: BuilderConstructor = function <T extends Node & Partial<With
199207

200208
type Arg = null | Builder | Node | string | Arg[] | Signal<Arg>;
201209

202-
return (target[targetName] ??= instancesOf(node[nodeName], Function) && !node.hasOwnProperty(nodeName)
210+
return (target[targetName] ??= instancesOf(node[nodeName], Function) && !Object.hasOwn(node, nodeName)
203211
? nodeName == targetName
204212
? (...args: unknown[]) => {
205213
(node[nodeName] as Fn)(...args);

0 commit comments

Comments
 (0)