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

Request TS | Is it correct that contentDialog handler methods require a Promise as a return value? #66

Open
BenJenkinson opened this issue Apr 8, 2022 · 1 comment

Comments

@BenJenkinson
Copy link
Contributor

The Typescript types specify that a Content Dialog's handler function must return a Promise<void>, in addition to accepting the resolve/reject arguments.

https://github.com/BEE-Plugin/Bee-plugin-official/blob/083ec76fd013087b8324703a55f01bcfe273e8fe/src/types/bee.ts#L286-L291

Returning a pending/resolve/rejected Promise seems to produce no effect,

The documentation doesn't mention a return value.

Isn't the handler just used as the function passed to new Promise(handler)? If it is, the return value of handler would be ignored.

Documentation

The Content Dialog documentation describes the handler method as follows:

handler

Is a function with a Promise-like signature.

This function lets you use your own logic to retrieve the desired value.
Once the value is available, you must call the resolve(value) function to pass it to the editor.
In case you want to cancel the operation, call the reject() function.

A resolve or reject call is mandatory. If you miss this step, the editor will remain in waiting mode.
Error management on the host application must call the reject function to unblock the editor.

The documentation gives several examples, none of which return anything from the handler method:

contentDialog: {
  filePicker: {
    handler: function(resolve, reject) {
      resolve({
        url: 'string', // url to the file (e.g. http://www.example.com/myimage.jpg)
      })
    }
  },
  specialLinks: {
    label: 'Custom text for links',
    handler: function(resolve, reject) {
      openMySpecialLinkDialog() // Replace this with your application function
        .then(specialLink => resolve(specialLink))
        .catch(() => reject())
    }
  },
}
@BenJenkinson
Copy link
Contributor Author

Hi @davidesamp, do you know the answer to this?

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

No branches or pull requests

1 participant