Comments (7)
workers have no dom, right? so I am not sure you're supposed to use CustomEvent within a worker, postMessage
is usually the channel. What am I missing?
from custom-event.
I don't see how postMessage would remove the need for CustomEvent if the app-architecture inside the worker makes use of it.
There has been a discussion about this in a w3 mailing list, too. The TL:DR is that the new CustomEvent constructor would make createEvent obsolete in a worker context, which it does... but apparently Safari never enabled the CustomEvent constructor in a worker context
from custom-event.
any reason not to use Event
instead? https://github.com/ungap/event
that does feature detection and it should patch Safari too.
from custom-event.
The reason to choose CustomEvent instead was the standardized details property, but I guess it would be possible to extend Event to create our own derived class... We'll consider doing so. You may close this issue if you have no intend to pursue this further! Thanks a lot for all your good work and help!
from custom-event.
@caritasverein the thing is, even IE11 fails at new CustomEvent
, so maybe fixing that in here would be better than pointing at Event
, as the detail
payload is handy indeed.
will try to fix this soon(ish)
from custom-event.
@caritasverein although ...
Safari never enabled the CustomEvent constructor in a worker context
how am I supposed to patch that in there?
from custom-event.
@caritasverein let's do this the other way around .... would this work?
/*! (c) Andrea Giammarchi - ISC */
var self = this || /* istanbul ignore next */ {};
try { new CustomEvent('!'); }
catch (shenanigans) {
self.CustomEvent = typeof document === typeof void 0 ?
// the Safari case
(function (CustomEvent) {
FakeCustomEvent.prototype = CustomEvent.prototype;
return FakeCustomEvent;
function FakeCustomEvent() {
return Reflect.construct(CustomEvent, arguments, this.constructor);
}
}(CustomEvent)) :
// the IE11 case
(function () {
FakeCustomEvent.prototype = CustomEvent.prototype;
return FakeCustomEvent;
function FakeCustomEvent(type, init) {
if (!init) init = {};
var e = document.createEvent('CustomEvent');
e.initCustomEvent(type, !!init.bubbles, !!init.cancelable, init.detail);
return e;
}
}());
}
from custom-event.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from custom-event.