Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/ui/src/dispatch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, expect, test } from 'vitest';
import { DispatchApi } from './dispatch.ts';
import { createHost } from './host.ts';

describe('dispatch', () => {
test('propagates errors thrown by decorators installed on the host', () => {
const host = createHost();
const reason = new Error('dispatch failed');
const dispatch = DispatchApi.init(host.root);
DispatchApi.decorate(host.root, () => ({
dispatch() {
throw reason;
},
}));

expect(() => dispatch.dispatch({})).toThrow(reason);
});
});
16 changes: 16 additions & 0 deletions packages/ui/src/dispatch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Api } from './core/api.ts';

export class DispatchApi extends Api {
dispatch(_event: unknown): Result {
return { ok: true };
}
}

export type Result =
| typeof Ok
| {
ok: false;
reason: unknown;
};

const Ok = { ok: true } as const;
1 change: 1 addition & 0 deletions packages/ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { rgba } from '@bomb.sh/tty';
export { DispatchApi } from './dispatch.ts';
export { box, type BoxProps } from './components/box.ts';
export { text, type TextProps } from './components/text.ts';
export { LayoutApi } from './layout.ts';
Expand Down
Loading