Git Product home page Git Product logo

event-target's Issues

Clean CJS form

Currently when requiring in CJS, (according to documentation) one has to do:

const EventTarget = require('event-target').default;

It'll be way more natural if it's:

const EventTarget = require('event-target');

Is this fixable?

CJS & browserify: EventTarget is not a constructor

I installed the module via npm, required it as said in the docs (Browserify 16.2.2 handles the bundling).

const EventTarget = require('event-target').default;

but I get an error:

Safari 11.1 (doesn't have EventTarget constructor)
TypeError: undefined is not a constructor (evaluating 'new EventTarget')

FF 61 (has support, works perfect w/o polyfill)
TypeError: EventTarget is not a constructor

Including the script tag from the CDN works though.

Support for instanceof

Following evaluate to false when setting window.EventTarget using the polyfill


import EventTarget from 'event-target/esm/index.js'

console.log(EventTarget instanceof window.EventTarget);

import EventTarget from 'event-target/esm/index.js'

console.log(document.createElement('div') instanceof EventTarget);

Not sure if it is possible to get either of these to evaluate to true..?

ES3 support

If I see correctly support for ES3 engines is not ensured.

(so Every. JavaScript. Engine. statement is not true ;-))

While it's not common to write for ES3 engines these days. It still can be the case in some scenarios, and EventTarget is core interface to many functionalities.

addEventListener with {once: true} in safari causes only first listener to be run

Seen in Safari 11.1
Works fine in Chrome 66.0.3359.139

Using browser event target implementation:

let eventTarget;
eventTarget = document.createElement('div');
eventTarget.addEventListener('foo', () => console.log(1), {once: true});
eventTarget.addEventListener('foo', () => console.log(2), {once: true});
eventTarget.dispatchEvent(new CustomEvent('foo'))

1
2

Using polyfill:

eventTarget = new EventTarget; 
eventTarget.addEventListener('foo', () => console.log(1), {once: true});
eventTarget.addEventListener('foo', () => console.log(2), {once: true});
eventTarget.dispatchEvent(new CustomEvent('foo'))

1

Using polyfill without once option:

eventTarget = new EventTarget; 
eventTarget.addEventListener('foo', () => console.log(1));
eventTarget.addEventListener('foo', () => console.log(2));
eventTarget.dispatchEvent(new CustomEvent('foo'))

1
2

I use the following with webpack to import the polyfill:

import EventTarget from 'event-target/esm/index.js';

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.