diff --git a/src/dom/h.ts b/src/dom/h.ts index 0c1fd57..8a55c7c 100644 --- a/src/dom/h.ts +++ b/src/dom/h.ts @@ -15,9 +15,8 @@ export function h( a?: DoomProperties | Children, b?: Children ): Element { - const { props, children } = prepare(a, b); const el: HTMLElementTagNameMap[K] = document.createElement(component as K); - const { ...properties } = props as DoomProperties; + const { properties, children } = prepareArguments(a, b); toProperties(properties as DoomProperties).forEach(({ key, value }) => { if (key === "style") { @@ -35,9 +34,7 @@ export function h( return; } - effect(() => { - el[key] = evaluate(value); - }); + effect(() => (el[key] = evaluate(value))); }); addChildren(el, children as Children); @@ -108,21 +105,21 @@ const pass = (prop: Reactive): T => prop as T; const evaluate = (prop: Reactive): T => typeof prop !== "function" ? prop : (prop as Function)(); -function prepare( +function prepareArguments( a: unknown, b: unknown ) { if (!a && !b) { - return { props: {} as DoomProperties, children: [] as Children }; + return { properties: {} as DoomProperties, children: [] as Children }; } if (!b) { if (Array.isArray(a) || typeof a === "function" || typeof a === "string") { - return { props: {} as DoomProperties, children: a as Children }; + return { properties: {} as DoomProperties, children: a as Children }; } else { - return { props: a as DoomProperties, children: [] as Children }; + return { properties: a as DoomProperties, children: [] as Children }; } } - return { props: a as DoomProperties, children: b as Children }; + return { properties: a as DoomProperties, children: b as Children }; } diff --git a/src/reactivity/utils/MapSet.ts b/src/reactivity/utils/MapSet.ts index ba2e17d..8385cea 100644 --- a/src/reactivity/utils/MapSet.ts +++ b/src/reactivity/utils/MapSet.ts @@ -14,8 +14,4 @@ export class MapSet { get(key: K | null): V[] { return (key && this.map.get(key)) || []; } - - first(key: K | null): V | null { - return (key && this.map.get(key)?.[0]) ?? null; - } } diff --git a/src/reactivity/utils/Subscriptions.ts b/src/reactivity/utils/Subscriptions.ts index ed165bb..71a6537 100644 --- a/src/reactivity/utils/Subscriptions.ts +++ b/src/reactivity/utils/Subscriptions.ts @@ -3,7 +3,7 @@ import { Subscriber, _Signal } from "../types"; export class Subscriptions { private currentSubscriber: Subscriber | null = null; - private ancestors = new MapSet<_Signal, _Signal>(); + private ancestors = new Map<_Signal, _Signal>(); private subscriptions = new MapSet<_Signal, Subscriber>(); run(subscriber: Subscriber, fn: () => void): void { @@ -22,7 +22,7 @@ export class Subscriptions { } if (subscriber.derived) { - this.ancestors.addTo(subscriber.derived, signal); + this.ancestors.set(subscriber.derived, signal); } this.subscriptions.addTo(this._getAncestor(signal), subscriber); @@ -36,7 +36,7 @@ export class Subscriptions { } private _getAncestor(signal: _Signal): _Signal { - const ancestor = this.ancestors.first(signal); + const ancestor = this.ancestors.get(signal); if (!ancestor) { return signal; }