From 9bf65cebb4a983bc8d8b525f7c7a9ab9fcdcdbbe Mon Sep 17 00:00:00 2001 From: Abhishiv Saxena Date: Thu, 17 Oct 2024 08:51:02 +0530 Subject: [PATCH] rf --- package.json | 2 +- src/core/state/store.ts | 2 +- src/dom/api.ts | 4 ++-- src/dom/dom.ts | 19 ++++++++++--------- src/dom/index.ts | 36 +++++++++++++++++------------------- src/dom/traverser.ts | 2 +- 6 files changed, 32 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 78a8b92..ffbff5d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "alfama", - "version": "1.3.12", + "version": "1.3.13", "author": "Abhishiv Saxena", "license": "MIT", "description": "Fine-grained reactive library with no compiler, no magic, and no virtual DOM", diff --git a/src/core/state/store.ts b/src/core/state/store.ts index a41876d..51087d3 100644 --- a/src/core/state/store.ts +++ b/src/core/state/store.ts @@ -53,7 +53,7 @@ const createStoreSubscription = ( const v = getValueUsingPath(manager.v as any, cursorPath); return v; } catch (e) { - console.log(wire, wire.stores, encodedCursor, manager.v); + // console.log(wire, wire.stores, encodedCursor, manager.v); throw e; } }; diff --git a/src/dom/api.ts b/src/dom/api.ts index 649774c..e9b3641 100644 --- a/src/dom/api.ts +++ b/src/dom/api.ts @@ -84,10 +84,10 @@ export const updateElement = ( export const getLiveFragmentChildNodes = (frag: LiveDocumentFragment) => { const els: Node[] = []; - let node: Node | null = frag.startMarker; + let node: Node | null = frag.start; while (node) { els.push(node); - if (node === frag.endMarker) { + if (node === frag.end) { break; } node = node.nextSibling; diff --git a/src/dom/dom.ts b/src/dom/dom.ts index a217f5e..ab5bb34 100644 --- a/src/dom/dom.ts +++ b/src/dom/dom.ts @@ -7,24 +7,25 @@ const createTextNode = (arg: string | number | boolean | null | undefined) => const createMarker = (text: string, owner: DocumentFragment) => { const marker = document.createComment(text); - (marker as any).__owner__ = owner; + // (marker as any).__owner__ = owner; return marker; }; +// important only use append/prepend export class LiveDocumentFragment extends DocumentFragment { - startMarker: Comment; - endMarker: Comment; + start: Comment; + end: Comment; constructor(t?: string) { super(); - this.startMarker = createMarker(`<${t}>`, this); - this.endMarker = createMarker(``, this); - super.append(this.startMarker, this.endMarker); + this.start = createMarker(`<${t}>`, this); + this.end = createMarker(``, this); + super.append(this.start, this.end); } append(...nodes: Node[]) { - this.endMarker.before(...nodes); + this.end.before(...nodes); } prepend(...nodes: Node[]) { - this.startMarker.after(...nodes); + this.start.after(...nodes); } } @@ -125,7 +126,7 @@ const setAttributeValue = ( if (el.tagName === "INPUT" && attr === "value") (el as HTMLInputElement).value = val; } catch (e) { - console.error(el, attr, val); + // console.error(el, attr, val); throw e; } }; diff --git a/src/dom/index.ts b/src/dom/index.ts index 81a7191..10b9f74 100644 --- a/src/dom/index.ts +++ b/src/dom/index.ts @@ -1,37 +1,36 @@ +import { StoreManager, Wire, wireReset } from "../core/state"; import * as DOMConstants from "../dom/constants"; -import { - Context, - ComponentUtils, - VElement, - Component, - ComponentVElement, - NativeVElement, - RenderContext, - TreeStep, -} from "./types"; +import { getCursorProxyMeta } from "../utils"; import { getRenderContext, renderTreeStep, rmNodes } from "./api"; -import { reifyTree } from "./traverser"; import type { GenericEventAttrs, HTMLAttrs, - SVGAttrs, HTMLElements, + SVGAttrs, SVGElements, - TargetedEvent, } from "./jsx"; -import { runWire, StoreManager, Wire, wireReset } from "../core/state"; -import { getCursorProxyMeta } from "../utils"; +import { + Component, + ComponentUtils, + ComponentVElement, + Context, + NativeVElement, + RenderContext, + TreeStep, + VElement, +} from "./types"; -export * from "./types"; -export * as DOMConstants from "./constants"; export { addNode, - removeNode, insertElement, removeElement, + removeNode, updateElement, } from "./api"; +export * as DOMConstants from "./constants"; export { reifyTree } from "./traverser"; +export * from "./types"; +export { h }; export function defineContext(arg?: string): Context { return { @@ -64,7 +63,6 @@ function h( t: t, } as ComponentVElement | NativeVElement; } -export { h }; export function render( element: VElement, diff --git a/src/dom/traverser.ts b/src/dom/traverser.ts index e097786..b6ef6f3 100644 --- a/src/dom/traverser.ts +++ b/src/dom/traverser.ts @@ -167,7 +167,7 @@ export const getTreeStep = ( onUnmount: [], } as ComponentTreeStep; } else { - console.error(el); + // console.error(el); throw createError(110); } }