Skip to content

Commit

Permalink
refactor(wasm-api): update INotify impl
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 25, 2023
1 parent 02d83e8 commit 07e884f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion packages/wasm-api/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type { Fn, IDeref, ILength } from "@thi.ng/api";
import type { EVENT_ALL, Fn, IDeref, ILength } from "@thi.ng/api";
import type { WasmBridge } from "./bridge.js";

export const EVENT_MEMORY_CHANGED = "memory-changed";
export const EVENT_PANIC = "panic";

export type BridgeEventType =
| typeof EVENT_MEMORY_CHANGED
| typeof EVENT_PANIC
| typeof EVENT_ALL;

export type BigIntArray = bigint[] | BigInt64Array | BigUint64Array;

export type ReadonlyWasmString = IDeref<string> &
Expand Down
9 changes: 5 additions & 4 deletions packages/wasm-api/src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EVENT_MEMORY_CHANGED,
EVENT_PANIC,
type BigIntArray,
type BridgeEventType,
type CoreAPI,
type IWasmAPI,
type IWasmMemoryAccess,
Expand Down Expand Up @@ -46,7 +47,7 @@ export const OutOfMemoryError = defError(() => "Out of memory");
*/
@INotifyMixin
export class WasmBridge<T extends WasmExports = WasmExports>
implements IWasmMemoryAccess, INotify
implements IWasmMemoryAccess, INotify<BridgeEventType>
{
readonly id = "wasmapi";

Expand Down Expand Up @@ -528,13 +529,13 @@ export class WasmBridge<T extends WasmExports = WasmExports>

/** {@inheritDoc @thi.ng/api#INotify.addListener} */
// @ts-ignore: mixin
addListener(id: string, fn: Listener, scope?: any): boolean {}
addListener(id: BridgeEventType, fn: Listener, scope?: any): boolean {}

/** {@inheritDoc @thi.ng/api#INotify.removeListener} */
// @ts-ignore: mixin
removeListener(id: string, fn: Listener, scope?: any): boolean {}
removeListener(id: BridgeEventType, fn: Listener, scope?: any): boolean {}

/** {@inheritDoc @thi.ng/api#INotify.notify} */
// @ts-ignore: mixin
notify(event: Event): boolean {}
notify(event: Event<BridgeEventType>): boolean {}
}

0 comments on commit 07e884f

Please sign in to comment.