Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: events/commands/types restructured #403

Merged
merged 2 commits into from
Feb 3, 2025

Conversation

Charlie-XIAO
Copy link
Contributor

@Charlie-XIAO Charlie-XIAO commented Feb 3, 2025

Events

All events are written in core/events.ts. Each event is separated by a single-dashed comment block, marking possible pairs of emitters/listeners. Each event has a payload, unless void. By default the payload types are not exported, except in special cases. Each event is an object that can contain the one or more of the following properties: on which corresponds to the listener, toCanvas which means emit to canvas, toManager which means emit to manager. In the future if needed, there might toAll. To use events, import { events } from "/path/to/core"; then do e.g. events.renderWidgets.on(...), events.updateSettings.toCanvas(...), etc.

Commands

All commands are written in core/commands.ts. Payload types are inlined. To use commands, import { commands } from "/path/to/core";, then do e.g. commands.setRenderReady(), etc.

Types (Shared)

All backend types are written in files under types/backend/, corresponding to the module that the type belongs to in the backend. For instance, types that comes from the config module are under types/backend/config.ts. Types related to events are commands are exceptions - they are colocated with the events and the commands. For frontend types, currently they should be declared under canvas and manager separately. The only item that is under types/frontend.ts for now will be removed in a subsequent PR to under manager. All types are re-exported under index.ts, which may also provide additional utilities as needed. To use shared types, import { ... } from "/path/to/types";. Non-shared types that are respectively under canvas and manager are not touched. Types for events and commands should be used via events.xxx and commands.xxx, where events and commands should be imported in the ways specified above.

@Charlie-XIAO Charlie-XIAO merged commit 9e7df8a into main Feb 3, 2025
11 checks passed
@Charlie-XIAO Charlie-XIAO deleted the refactor/core-and-types branch February 3, 2025 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant