-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Web API: CustomEvent #1505
Conversation
isTrusted: value, | ||
target: this.target, | ||
timeStamp: this.timeStamp | ||
}); |
There was a problem hiding this comment.
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
.
js/custom_event.ts
Outdated
|
||
export class CustomEventInit extends event.EventInit | ||
implements domTypes.CustomEventInit { | ||
detail = null; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
js/custom_event.ts
Outdated
} | ||
|
||
// tslint:disable-next-line:no-any | ||
get detail(): any | null { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any | null
is any
js/custom_event.ts
Outdated
bubbles?: boolean, | ||
cancelable?: boolean, | ||
// tslint:disable-next-line:no-any | ||
detail?: any | null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any | null
is any
There was a problem hiding this 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
js/custom_event.ts
Outdated
customEventInitDict: domTypes.CustomEventInit = {} | ||
) { | ||
super(type, customEventInitDict); | ||
customEventAttributes.set(this, { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all set, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR builds off of my previous one to extend
Event
with the CustomEvent Web API spec.