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

Cleanup JS api types #3131

Open
wants to merge 8 commits into
base: v3-alpha
Choose a base branch
from
Open

Conversation

jpatters
Copy link

Description

The adds better type support for the js apis. It also makes the exports from the npm package more conventional. Previously usage looked like this:

import { Dialogs } from "@wailsapp/api";

Dialogs.Dialog.Info({Message: "hello world"});

usage now looks like this

import { Dialog } from "@wailsapp/api";

Dialog.Info({Message: "hello world"});

Because of the import change, I have marked this as a breaking change however, the documentation in the readme for the js package already described it as working this way even though it did not.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link

netlify bot commented Dec 14, 2023

‼️ Deploy request for dapper-pastelito-9b5e5b rejected.

Name Link
🔨 Latest commit df01313

Copy link
Contributor

coderabbitai bot commented Dec 14, 2023

Important

Auto Review Skipped

Auto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

*/
Center: () => void wails.Window.Center(),
/**
* Set the window title.
* @param title
* @param {string} title
* @returns {Promise<void>}
Copy link
Member

Choose a reason for hiding this comment

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

I believe void will mean nothing is returned?

Copy link
Author

Choose a reason for hiding this comment

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

I believe the function that it calls also returns Promise<void>. (https://github.com/jpatters/wails/blob/js-api-types/v3/internal/runtime/desktop/window.js#L65).

And when I followed it up the chain, it ended up here: https://github.com/jpatters/wails/blob/js-api-types/v3/internal/runtime/desktop/runtime.js#L84

Is this incorrect?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah the call to the backend returns a promise but the void here ignores it and returns nothing at all.

Copy link
Author

Choose a reason for hiding this comment

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

Ok. Happy to update. What is the desired behaviour? I would have expected a promise.

Copy link
Member

Choose a reason for hiding this comment

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

There's nothing to wait for as there's nothing being returned so it works like a normal synchronous function I guess.

Copy link
Author

Choose a reason for hiding this comment

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

I see. Is there an opportunity for the request to the backend to fail though? Should the promise propagate up?

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe so but we could make promise a standard regardless. Just had PRs in the past to remove that when they don't return anything.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah. If there's no opportunity for the request from the backend to be rejected then that makes sense for sure. I'll dig through some more code to see what might happen on the backend and come back with a stronger opinion.

Copy link
Member

Choose a reason for hiding this comment

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

As you rightly said, those wrappers are out of date so they very well may have changed.

Copy link
Author

Choose a reason for hiding this comment

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

So, the backend does return http errors when things go wrong and the response handler does properly call reject when the http code is not in the 200 range. So I would suggest not swallowing those errors and allowing the promise to propagate up to the caller. It will require a few more changes for this to all behave as expected as the method that this calls also swallows the rejection. But minor changes. If this sounds reasonable, I will make the changes in this pr.

@leaanthony
Copy link
Member

Please could you update the changelog located at mkdocs-website/docs/changelog.md? The one in the PR is for v2, Thanks!

@jpatters
Copy link
Author

Please could you update the changelog located at mkdocs-website/docs/changelog.md? The one in the PR is for v2, Thanks!

Ah. Good to know. Thanks.

@leaanthony
Copy link
Member

@jpatters - A lot has gone on since this PR was open. Let's discuss on discord 🙏

@jpatters
Copy link
Author

jpatters commented Jan 5, 2024

@jpatters - A lot has gone on since this PR was open. Let's discuss on discord 🙏

Yeah, for sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants