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

feat: add support for objects containing toPromise method #1998

Merged
merged 1 commit into from
Jun 13, 2020
Merged

feat: add support for objects containing toPromise method #1998

merged 1 commit into from
Jun 13, 2020

Conversation

rafaelss95
Copy link
Contributor

Closes #1982.

@rafaelss95
Copy link
Contributor Author

@limonte it's still under development. I need some guidance in the tests creation. Could you help me there? BTW, this is more or less the correct flux to implement this?

@limonte limonte requested a review from zenflow June 9, 2020 09:47
Copy link
Member

@zenflow zenflow left a comment

Choose a reason for hiding this comment

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

Overall it looks great! Just a couple nits about naming and types. See inline comments.

sweetalert2.d.ts Outdated
@@ -337,6 +337,10 @@ declare module 'sweetalert2' {
const version: string
}

interface Promisify<T> {
readonly toPromise: () => T;
Copy link
Member

Choose a reason for hiding this comment

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

We don't require the toPromise member to be readonly do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, readonly for this case doesn't matter at all.

sweetalert2.d.ts Outdated
@@ -387,7 +391,7 @@ declare module 'sweetalert2' {

type Awaited<T> = T extends Promise<infer U> ? U : T;

type SyncOrAsync<T> = T | Promise<T>;
type SyncOrAsync<T> = T | Promise<T> | Promisify<T>;
Copy link
Member

Choose a reason for hiding this comment

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

I think we can inline Promisify here, since it's only used once, and probably will only ever be used once. This makes it easier to see what SyncOrAsync is. This also saves us needing to name it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

export const isPromise = (arg) => arg && Promise.resolve(arg) === arg

export const promisify = (arg) => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg)
Copy link
Member

Choose a reason for hiding this comment

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

The verb "promisify" has been used a lot to describe converting a callback-based API to a Promise-based API. For example, NodeJS's util.promisify, Bluebird's Promise.promisify, pify, and more. I suggest renaming to something else. Ideas: toPromise or asPromise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated it to asPromise.

@zenflow
Copy link
Member

zenflow commented Jun 12, 2020

I need some guidance in the tests creation. Could you help me there?

@rafaelss95 What in particular do you need guidance on? Are you familiar with automated testing in general? Were you able to run the tests locally? Maybe you need help choosing which tests to update?

BTW, this is more or less the correct flux to implement this?

Not totally sure what you mean by correct "flux".. Can you clarify? Or maybe this doesn't concern me.

@rafaelss95
Copy link
Contributor Author

Maybe you need help choosing which tests to update?

Yep, I wasn't sure which tests should be updated. I've checked the https://github.com/sweetalert2/sweetalert2#contributing and it doesn't contain anything about the tests.

Not totally sure what you mean by correct "flux".. Can you clarify? Or maybe this doesn't concern me.

As it's my first contribution to this repository, in addition to types, I was asking if the implementation had followed the guidelines.

@rafaelss95
Copy link
Contributor Author

@limonte @zenflow I added some tests for this and I guess it's ready to review now.

PS: Note that I also added tests for inputOptions using Promise that didn't exist before.

@rafaelss95 rafaelss95 requested a review from zenflow June 13, 2020 18:43
@rafaelss95 rafaelss95 marked this pull request as ready for review June 13, 2020 19:33
Copy link
Member

@limonte limonte left a comment

Choose a reason for hiding this comment

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

Great contribution, thank you @rafaelss95!

@limonte limonte merged commit 0d33441 into sweetalert2:master Jun 13, 2020
@rafaelss95 rafaelss95 deleted the feat/support-object-with-to-promise branch June 13, 2020 21:14
limonte pushed a commit that referenced this pull request Jun 13, 2020
# [9.15.0](v9.14.4...v9.15.0) (2020-06-13)

### Features

* add support for objects containing toPromise method ([#1998](#1998)) ([0d33441](0d33441))
@limonte
Copy link
Member

limonte commented Jun 13, 2020

🎉 This PR is included in version 9.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

limonte added a commit that referenced this pull request Jun 14, 2020
limonte added a commit that referenced this pull request Jun 14, 2020
matvejs16 pushed a commit to matvejs16/sweetalert2-fix that referenced this pull request Mar 29, 2023
matvejs16 pushed a commit to matvejs16/sweetalert2-fix that referenced this pull request Mar 29, 2023
# [9.15.0](sweetalert2/sweetalert2@v9.14.4...v9.15.0) (2020-06-13)

### Features

* add support for objects containing toPromise method ([sweetalert2#1998](sweetalert2#1998)) ([3360a33](sweetalert2@3360a33))
matvejs16 pushed a commit to matvejs16/sweetalert2-fix that referenced this pull request Mar 29, 2023
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.

Support ObservableLike
3 participants