diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-04-14 00:34:41 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-04-14 00:34:41 +0300 |
| commit | 53c9dad18a612c97cacc3c0fe5eeb01e6ffcc026 (patch) | |
| tree | ddbe9984799b340554ce30b126904f119be121c5 | |
| parent | 517e45f01af67a22677ae99ca44593f8f0d52057 (diff) | |
Rename EventX to ShapeX
The project is renamed from EventX to ShapeX, updating all references in code,
documentation and package metadata.
| -rw-r--r-- | README.md | 20 | ||||
| -rw-r--r-- | package.json | 12 | ||||
| -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 | ||||
| -rw-r--r-- | tsup.config.ts | 2 |
5 files changed, 36 insertions, 36 deletions
@@ -1,19 +1,19 @@ -# EventX +# ShapeX -Create scaleable event-driven applications with EventX, inspired by [re-frame](https://github.com/day8/re-frame/). EventX uses zero dependencies and is runtime agnostic, meaning that you can use it in Node, Deno, Bun, browsers, or really anywhere where JavaScript runs. +Create scalable event-driven applications with ShapeX, inspired by [re-frame](https://github.com/day8/re-frame/). ShapeX uses zero dependencies and is runtime agnostic, meaning that you can use it in Node, Deno, Bun, browsers, or really anywhere where JavaScript runs. ## Example application -This is an example application that demonstrates how to use the EventX library. It has a single starting point event called `request`, which returns an updated state, which changes the `counter`. When that state changes, the subscriber for the `counter` state fires. +This is an example application that demonstrates how to use the ShapeX library. It has a single starting point event called `request`, which returns an updated state, which changes the `counter`. When that state changes, the subscriber for the `counter` state fires. ```typescript -import EventX from "@askonmm/eventx"; +import ShapeX from "ShapeX"; type AppState = { counter: number; }; -const $ = EventX<AppState>({ +const $ = ShapeX<AppState>({ counter: 1, }); @@ -41,23 +41,23 @@ $.dispatch("request"); ## Installation ```shell -npm i @askonmm/eventx +npm i shapex ``` ## Documentation ### State -At the core of your application is state. You start by initiating EventX with some initial state, like so: +At the core of your application is state. You start by initiating ShapeX with some initial state, like so: ```typescript -import EventX from "@askonmm/eventx"; +import ShapeX from "shapex"; type AppState = { counter: number; }; -const $ = EventX<AppState>({ +const $ = ShapeX<AppState>({ counter: 1, }); ``` @@ -109,7 +109,7 @@ $.subscribe("$counter", (state) => { }); ``` -Notable difference here is the `$` prefix in the subscription listener name, which tells EventX what state to look for. Here `$counter` will look for the root-level `counter` key in state. To look for nested state, simply add a dot (`.`) followed by the key name, i.e: `$counter.nestedKey`. Additionally, state change subscriptions do not get any additional data passed to them, only state. +Notable difference here is the `$` prefix in the subscription listener name, which tells ShapeX what state to look for. Here `$counter` will look for the root-level `counter` key in state. To look for nested state, simply add a dot (`.`) followed by the key name, i.e: `$counter.nestedKey`. Additionally, state change subscriptions do not get any additional data passed to them, only state. #### Subscribe only once diff --git a/package.json b/package.json index 785e2e8..8e36f70 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { - "name": "@askonmm/eventx", + "name": "shapex", "version": "1.0.3", "description": "A scalable event-driven application framework.", - "main": "dist/eventx.cjs", - "module": "dist/eventx.js", + "main": "dist/shapex.cjs", + "module": "dist/shapex.js", "type": "module", "license": "MIT", "keywords": [ @@ -13,15 +13,15 @@ "subscriptions" ], "bugs": { - "url": "https://github.com/askonomm/eventx/issues", + "url": "https://github.com/askonomm/shapex/issues", "email": "asko@nmm.ee" }, "repository": { "type": "git", - "url": "git+https://github.com/askonomm/eventx.git" + "url": "git+https://github.com/askonomm/shapex.git" }, "scripts": { - "bundle": "tsup src/eventx.ts", + "bundle": "tsup src/shapex.ts", "test": "vitest", "coverage": "vitest run --coverage" }, 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; diff --git a/tsup.config.ts b/tsup.config.ts index 13e76f2..74dcfd7 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,7 +1,7 @@ import { defineConfig } from "tsup"; export default defineConfig({ - entry: ["src/eventx.ts"], + entry: ["src/shapex.ts"], clean: true, format: ["esm", "cjs"], dts: true, |
