summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2025-04-14 00:34:41 +0300
committerAsko Nõmm <asko@nmm.ee>2025-04-14 00:34:41 +0300
commit53c9dad18a612c97cacc3c0fe5eeb01e6ffcc026 (patch)
treeddbe9984799b340554ce30b126904f119be121c5 /src
parent517e45f01af67a22677ae99ca44593f8f0d52057 (diff)
Rename EventX to ShapeX
The project is renamed from EventX to ShapeX, updating all references in code, documentation and package metadata.
Diffstat (limited to 'src')
-rw-r--r--src/shapex.test.ts (renamed from src/eventx.test.ts)32
-rw-r--r--src/shapex.ts (renamed from src/eventx.ts)6
2 files changed, 19 insertions, 19 deletions
diff --git a/src/eventx.test.ts b/src/shapex.test.ts
index bb47449..aadeea7 100644
--- a/src/eventx.test.ts
+++ b/src/shapex.test.ts
@@ -1,17 +1,17 @@
import { describe, test, expect, vi, beforeEach } from "vitest";
-import EventX from "./eventx";
+import ShapeX from "./shapex.ts";
describe("EventX", () => {
describe("subscribe", () => {
test("subscribes to an event", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
const id = $.subscribe("test-event", (state) => ({ state }));
expect(id).toBe(1);
expect($.subscriptionCount("test-event")).toBe(1);
});
test("subscribes to an event once", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
const id = $.subscribeOnce("test-event", (state) => ({ state }));
expect(id).toBe(1);
expect($.subscriptionCount("test-event")).toBe(1);
@@ -22,7 +22,7 @@ describe("EventX", () => {
});
test("unsubscribes from an event", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
$.subscribe("test-event", (state) => ({ state }));
expect($.subscriptionCount("test-event")).toBe(1);
@@ -33,7 +33,7 @@ describe("EventX", () => {
describe("dispatch", () => {
test("dispatches an event without arguments", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
const callback = vi.fn((state) => ({ state }));
$.subscribe("test-event", callback);
@@ -44,7 +44,7 @@ describe("EventX", () => {
});
test("dispatches an event with arguments", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
const callback = vi.fn((state, arg1, arg2) => ({ state }));
$.subscribe("test-event", callback);
@@ -55,7 +55,7 @@ describe("EventX", () => {
});
test("updates state when event handler returns new state", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
const stateChangeSpy = vi.fn((state) => ({ state }));
$.subscribe("$counter", stateChangeSpy);
@@ -70,7 +70,7 @@ describe("EventX", () => {
});
test("dispatches nested events", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
const nestedEventSpy = vi.fn((state) => ({ state }));
$.subscribe("nested-event", nestedEventSpy);
@@ -85,7 +85,7 @@ describe("EventX", () => {
});
test("dispatches multiple nested events", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
const nestedEvent1Spy = vi.fn((state) => ({ state }));
const nestedEvent2Spy = vi.fn((state) => ({ state }));
@@ -103,7 +103,7 @@ describe("EventX", () => {
});
test("dispatches nested events with arguments", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
const nestedEventSpy = vi.fn((state, arg) => ({ state }));
$.subscribe("nested-event", nestedEventSpy);
@@ -121,7 +121,7 @@ describe("EventX", () => {
describe("state change detection", () => {
test("detects value changes in state", () => {
- const $ = EventX({ counter: 1, nested: { value: "test" } });
+ const $ = ShapeX({ counter: 1, nested: { value: "test" } });
const counterChangeSpy = vi.fn((state) => ({ state }));
$.subscribe("$counter", counterChangeSpy);
@@ -136,7 +136,7 @@ describe("EventX", () => {
});
test("detects nested value changes in state", () => {
- const $ = EventX({ counter: 1, nested: { value: "test" } });
+ const $ = ShapeX({ counter: 1, nested: { value: "test" } });
const nestedValueChangeSpy = vi.fn((state) => ({ state }));
$.subscribe("$nested.value", nestedValueChangeSpy);
@@ -157,7 +157,7 @@ describe("EventX", () => {
});
test("detects deleted properties in state", () => {
- const $ = EventX({ counter: 1, toDelete: "value" } as { counter: number; toDelete?: string });
+ const $ = ShapeX({ counter: 1, toDelete: "value" } as { counter: number; toDelete?: string });
const deleteChangeSpy = vi.fn((state) => ({ state }));
$.subscribe("$toDelete", deleteChangeSpy);
@@ -172,7 +172,7 @@ describe("EventX", () => {
});
test("detects type changes in state", () => {
- const $ = EventX({ counter: 1 } as { counter: string | number });
+ const $ = ShapeX({ counter: 1 } as { counter: string | number });
const counterChangeSpy = vi.fn((state) => ({ state }));
$.subscribe("$counter", counterChangeSpy);
@@ -188,7 +188,7 @@ describe("EventX", () => {
describe("utility methods", () => {
test("returns all subscription names", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
$.subscribe("event1", (state) => ({ state }));
$.subscribe("event2", (state) => ({ state }));
@@ -199,7 +199,7 @@ describe("EventX", () => {
});
test("returns subscription count for specific event", () => {
- const $ = EventX({ counter: 1 });
+ const $ = ShapeX({ counter: 1 });
$.subscribe("event1", (state) => ({ state }));
$.subscribe("event1", (state) => ({ state }));
$.subscribe("event2", (state) => ({ state }));
diff --git a/src/eventx.ts b/src/shapex.ts
index 0e108d9..93f40e7 100644
--- a/src/eventx.ts
+++ b/src/shapex.ts
@@ -24,7 +24,7 @@ export type Subscription<T> = {
export type StateChange = "deleted" | "changed-type" | "changed-value";
-export type EventX<T> = {
+export type ShapeX<T> = {
subscribe: (listener: string, callback: EventCallback<T>) => number;
subscribeOnce: (listener: string, callback: EventCallback<T>) => number;
unsubscribe: (listener: string) => void;
@@ -39,7 +39,7 @@ export type EventX<T> = {
* @param {T extends object} initialState The initial application state.
* @returns {EventX<T>} The EventX object.
*/
-const EventX = <T extends object>(initialState: T): EventX<T> => {
+const ShapeX = <T extends object>(initialState: T): ShapeX<T> => {
let _state = initialState;
const _subscriptions: Map<string, Subscription<T>[]> = new Map();
let subscriptionId = 0;
@@ -231,4 +231,4 @@ const EventX = <T extends object>(initialState: T): EventX<T> => {
};
};
-export default EventX;
+export default ShapeX;