Skip to content

Instantly share code, notes, and snippets.

@yigaldviri
yigaldviri / shim-xhr-to-fetch.js
Created October 2, 2019 11:46
A shim file to replace the use of `XMLHttpRequest` with 'fetch'. Meant for supporting libraries in a service-worker's scope
class Dispatch extends EventTarget {
dispatch(eventName) {
const ev = new Event(eventName);
if (("on" + eventName) in this) {
this["on" + eventName](ev);
}
this.dispatchEvent(ev);
}