diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-04-19 18:49:32 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-04-19 18:49:32 +0300 |
| commit | 08ed3d406f178f372899fd76b982bf20597756c1 (patch) | |
| tree | db7a69d8dbe770b333c6bb9cba715fb947a43d0a /src/shapex.test.ts | |
| parent | 92ae308186773a8f8bfd013259aeeb31d27aaaa9 (diff) | |
Impl generics on dispatch/subscription arguments.
Diffstat (limited to 'src/shapex.test.ts')
| -rw-r--r-- | src/shapex.test.ts | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/shapex.test.ts b/src/shapex.test.ts index 35207bb..de40708 100644 --- a/src/shapex.test.ts +++ b/src/shapex.test.ts @@ -56,8 +56,13 @@ describe("dispatch", () => { const $ = ShapeX<AppState>({ counter: 1 }); - // deno-lint-ignore no-unused-vars - const testEventCb: EventCallback<AppState> = (state, arg1, arg2) => ({ + const testEventCb: EventCallback<AppState, [string, string]> = ( + state, + // deno-lint-ignore no-unused-vars + arg1, + // deno-lint-ignore no-unused-vars + arg2 + ) => ({ state, }); @@ -67,11 +72,7 @@ describe("dispatch", () => { $.dispatch("test-event", "arg1-value", "arg2-value"); assertSpyCall(callback, 0, { - args: [ - { counter: 1 }, - "arg1-value", - "arg2-value", - ], + args: [{ counter: 1 }, "arg1-value", "arg2-value"], }); }); @@ -93,9 +94,7 @@ describe("dispatch", () => { $.dispatch("increment"); assertSpyCall(spyCb, 0, { - args: [ - { counter: 2 }, - ], + args: [{ counter: 2 }], }); }); @@ -136,9 +135,12 @@ describe("dispatch", () => { $.subscribe("parent-event", (state) => ({ state, - dispatch: [{ eventName: "nested-event-1" }, { - eventName: "nested-event-2", - }], + dispatch: [ + { eventName: "nested-event-1" }, + { + eventName: "nested-event-2", + }, + ], })); $.dispatch("parent-event"); @@ -154,7 +156,7 @@ describe("dispatch", () => { const $ = ShapeX<AppState>({ counter: 1 }); // deno-lint-ignore no-unused-vars - const cb: EventCallback<AppState> = (state, arg) => ({ state }); + const cb: EventCallback<AppState, [string]> = (state, arg) => ({ state }); const spyCb = spy(cb); $.subscribe("nested-event", spyCb); @@ -368,10 +370,9 @@ describe("utility methods", () => { it("returns updated state", () => { const $ = ShapeX({ counter: 1 }); - $.subscribe( - "event1", - (state) => ({ state: { counter: state.counter + 1 } }), - ); + $.subscribe("event1", (state) => ({ + state: { counter: state.counter + 1 }, + })); $.dispatch("event1"); |
