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

Using "Event" constructor should be replaced by "CustomEvent" constructor? (IE11 compatibility) #392

Open
jybleau opened this issue May 11, 2020 · 0 comments

Comments

@jybleau
Copy link

jybleau commented May 11, 2020

Firstly, I can create a PR if you want...

I have a problem with those lines in IE11:

const event = new Event('pnotify:position');

const eventObj = new Event(`pnotify:${event}`, {

There is a bug when including @pnotify/core/dist/PNotify.js :
Calling new Event(...) fails and it seems it's not safe/recommended to replace it with a polyfill directly... (Some say yes, some say no; MDN does not suggest to do so...)

Instead of trying to transpile (if it would rewrite this code correctly?), I found out we should instead be creating an event using the new CustomEvent(...) constructor
Ref to the API:
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent

This API does not exists in IE11 but then it can be safely added as a polyfill as described in the MDN Web Docs, and it works fine.

PS: If I understand correctly your README file, the dist/Pnotify.js can be used in ES5 browsers. And I already include es5 and es6 shims in my projects and Pnotify is working fine so far when combined with the use of CustomEvent API and a polyfill of course.

PS2: Another related issue: Setting the Event.detail property after the event has been created is not suppose to work in strict mode (it is supposed to be a RO property); it should instead be included with the parameters in the call to the contructor.
here:

eventObj.detail = eventDetail;

And here is how I modified the code:
jybleau@f3ef80f

Anyway, what do you think about that?

Thanks

@jybleau jybleau changed the title Using "Event" constructor should be replaced by the "CustomEvent" one? (IE11 compatibility) Using "Event" constructor should be replaced by "CustomEvent" constructor? (IE11 compatibility) May 11, 2020
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