Skip to content

Commit

Permalink
v1.3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishiv committed Oct 16, 2024
1 parent 3fdf78e commit 9687448
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alfama",
"version": "1.3.9",
"version": "1.3.10",
"author": "Abhishiv Saxena<abhishiv@gmail.com>",
"license": "MIT",
"description": "Fine-grained reactive library with no compiler, no magic, and no virtual DOM",
Expand Down
16 changes: 6 additions & 10 deletions src/dom/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
RenderContext,
ComponentTreeStep,
ComponentUtils,
EEmitter,
} from "./types";
import {
getDescendants,
Expand Down Expand Up @@ -201,15 +200,12 @@ export const getRenderContext = (
const id = getVirtualElementId(element);
if (!id) throw createError(101);

const renderContext: RenderContext =
(container as any)[id] ||
({
prevState: new Map(),
el: container,
id,
reg: new Set(),
emitter: new EEmitter(),
} as RenderContext);
const renderContext: RenderContext = (container as any)[id] || {
prevState: new Map(),
el: container,
id,
reg: new Set(),
};

//console.log("renderContext", renderContext);
renderContext.prevState.clear();
Expand Down
22 changes: 0 additions & 22 deletions src/dom/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,31 +118,9 @@ export interface RenderContext {
el: Element;
prevState: Map<string[], ComponentTreeStepState>;
reg: Set<TreeStep>;
emitter: EEmitter;
}

// Context like you'll find in react/solid
export type Context<T = Signal | StoreCursor> = {
sym: symbol;
};

export class EEmitter {
t: EventTarget;
constructor() {
this.t = new EventTarget();
}
on(eventName: string, listener: EventListenerOrEventListenerObject | null) {
return this.t.addEventListener(eventName, listener);
}
once(eventName: string, listener: EventListenerOrEventListenerObject | null) {
return this.t.addEventListener(eventName, listener, { once: true });
}
off(eventName: string, listener: EventListenerOrEventListenerObject | null) {
return this.t.removeEventListener(eventName, listener);
}
emit(eventName: string, detail: any) {
return this.t.dispatchEvent(
new CustomEvent(eventName, { detail, cancelable: true })
);
}
}

0 comments on commit 9687448

Please sign in to comment.