GithubHelp home page GithubHelp logo

Comments (7)

WebReflection avatar WebReflection commented on August 12, 2024

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.

caritasverein avatar caritasverein commented on August 12, 2024

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.

WebReflection avatar WebReflection commented on August 12, 2024

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.

caritasverein avatar caritasverein commented on August 12, 2024

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.

WebReflection avatar WebReflection commented on August 12, 2024

@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.

WebReflection avatar WebReflection commented on August 12, 2024

@caritasverein although ...

Safari never enabled the CustomEvent constructor in a worker context

how am I supposed to patch that in there?

from custom-event.

WebReflection avatar WebReflection commented on August 12, 2024

@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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.