refactor: events/commands/types restructured #403
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, unlessvoid
. 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 mighttoAll
. 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 theconfig
module are undertypes/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 undercanvas
andmanager
separately. The only item that is undertypes/frontend.ts
for now will be removed in a subsequent PR to undermanager
. All types are re-exported underindex.ts
, which may also provide additional utilities as needed. To use shared types,import { ... } from "/path/to/types";
. Non-shared types that are respectively undercanvas
andmanager
are not touched. Types for events and commands should be used viaevents.xxx
andcommands.xxx
, whereevents
andcommands
should be imported in the ways specified above.