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

Web API: CustomEvent #1505

Merged
merged 3 commits into from
Jan 23, 2019
Merged

Web API: CustomEvent #1505

merged 3 commits into from
Jan 23, 2019

Conversation

acconrad
Copy link
Contributor

@acconrad acconrad commented Jan 12, 2019

This PR builds off of my previous one to extend Event with the CustomEvent Web API spec.

isTrusted: value,
target: this.target,
timeStamp: this.timeStamp
});
Copy link
Contributor Author

@acconrad acconrad Jan 12, 2019

Choose a reason for hiding this comment

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

the addition of these flags and the setter is in preparation for my EventTarget implementation, which will also rely on CustomEvent.

@acconrad
Copy link
Contributor Author

acconrad commented Jan 12, 2019

Probably should be reviewed by @ry and/or @kitsonk given the prior knowledge of the previous PR.

@acconrad
Copy link
Contributor Author

@ry @kitsonk sorry to bug again, but any chance someone can look at that Travis error? I'm a bit stuck on how to get this Typescript error to pass. Once it passes it should be ready for review since it's a pretty small implementation.


export class CustomEventInit extends event.EventInit
implements domTypes.CustomEventInit {
detail = null;
Copy link
Contributor

@kevinkassimo kevinkassimo Jan 21, 2019

Choose a reason for hiding this comment

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

Probably detail: any | null = null?

Travis is complaining that you cannot assign non-null values to detail of type null

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 but any | null would be just any.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, you are double initialising this... I would simply do:

detail: any;

Here and you have a default argument in the constructor which is then assigning to detail on construction. Also, I am not sure, but is detail readonly?

bubbles = false,
cancelable = false,
composed = false,
detail = null
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, the problem is coming here. The constructor signature looks like this because it is inferring the default arguments:

constructor(bubbles?: boolean, cancelable?: boolean, composed?: boolean, detail?: null)

This isn't what you want. You should be explicit about the type of detail at least.

}

// tslint:disable-next-line:no-any
get detail(): any | null {
Copy link
Contributor

Choose a reason for hiding this comment

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

any | null is any

bubbles?: boolean,
cancelable?: boolean,
// tslint:disable-next-line:no-any
detail?: any | null
Copy link
Contributor

Choose a reason for hiding this comment

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

any | null is any

@acconrad
Copy link
Contributor Author

Woo @kitsonk @ry it's passing so I'm ready for review! Thank you for the help!

Copy link
Contributor

@kitsonk kitsonk left a comment

Choose a reason for hiding this comment

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

LGTM, one minor bit of feedback

customEventInitDict: domTypes.CustomEventInit = {}
) {
super(type, customEventInitDict);
customEventAttributes.set(this, {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you wanted to deal with this even better you could do:

const { detail = null } = customEventInitDict;
customEventAttributes.set(this, { detail });

That is destructuring assignment with a default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all set, thanks!

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM thanks @acconrad
(And thx for the review @kitsonk )

@ry ry merged commit e470f31 into denoland:master Jan 23, 2019
@acconrad acconrad deleted the acc-add-web-api-custom-event branch February 22, 2019 17:03
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.

None yet

4 participants