Skip to content

Refactor startup promise orchestration#157

Open
Mahathi-s154 wants to merge 1 commit intojoplin:masterfrom
Mahathi-s154:refactor-startup-promise-orchestration
Open

Refactor startup promise orchestration#157
Mahathi-s154 wants to merge 1 commit intojoplin:masterfrom
Mahathi-s154:refactor-startup-promise-orchestration

Conversation

@Mahathi-s154
Copy link
Copy Markdown

Summary

  • replace the mixed named/unnamed PromiseGroup abstraction with a typed resolveNamedPromises helper
  • use native Promise.all for notebook display aggregation and command registration
  • add focused tests for the new promise resolver and wait for toolbar button creation after command registration

Testing

  • npm test -- --runInBand
  • npm run lint

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors startup async orchestration by removing the custom PromiseGroup abstraction and replacing it with a typed resolveNamedPromises helper, while simplifying other aggregation points to use native Promise.all.

Changes:

  • Replace PromiseGroup with resolveNamedPromises for resolving keyed async dependencies.
  • Use Promise.all directly for notebook display data aggregation and command registrations.
  • Add unit tests for resolveNamedPromises and ensure toolbar button creation happens after command registration completes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/utils/promises.ts Removes PromiseGroup and adds resolveNamedPromises for typed named-promise resolution.
src/index.ts Updates startup logic to use resolveNamedPromises / Promise.all, and awaits command registration before creating toolbar buttons.
tests/utils/promises.spec.ts Adds focused Jest coverage for resolveNamedPromises behavior (resolve/empty/reject).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +249 to +254
execute: async (folderId: string) => {
if (typeof folderId === "undefined") {
const selectedFolder = await joplin.workspace.selectedFolder();
folderId = selectedFolder.id;
}
await joplin.clipboard.writeText(folderId);
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the copyFolderID command, the execute callback parameter is typed as folderId: string but the implementation explicitly handles it being undefined. This type mismatch can hide issues and makes the code harder to reason about under strict null checks. Update the signature to accept string | undefined (or make it optional) and prefer const effectiveId = folderId ?? (await joplin.workspace.selectedFolder()).id; to avoid reassigning the parameter.

Suggested change
execute: async (folderId: string) => {
if (typeof folderId === "undefined") {
const selectedFolder = await joplin.workspace.selectedFolder();
folderId = selectedFolder.id;
}
await joplin.clipboard.writeText(folderId);
execute: async (folderId?: string) => {
const effectiveId = folderId ?? (await joplin.workspace.selectedFolder()).id;
await joplin.clipboard.writeText(effectiveId);

Copilot uses AI. Check for mistakes.
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.

2 participants