Giter Site home page Giter Site logo

event-target's People

Contributors

ayc0 avatar jccr avatar webreflection avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

event-target's Issues

Event bubbling

What is the issue?

Currently when dispatching an event to a node, that event won't bubble up to parents.
This is also used in linkedom which is the reason I started looking at it.

What could be done?

I pulled the code and started an update:

    define(proto, 'dispatchEvent', function (event) {
      var secret = wm.get(this);
      if (secret[event.type]) {
        var listeners = secret[event.type].slice(0);
        define(event, 'target', this);
        define(event, 'currentTarget', this);

        // if an event listener invoke stopImmediatePropagation it should stop calling other listeners
        for (var i = 0; i < listeners.length && !event._stopImmediatePropagationFlag; i++) {
          dispatch.call(event, listeners[i]);
        }
        delete event.currentTarget;
        delete event.target;
      }

      // should probably be done differently: https://dom.spec.whatwg.org/#event-path
      // but should not be too much of an issue for now
      if (event.bubbles && !event._stopPropagationFlag) {
        if (this.parentNode) {
          this.parentNode.dispatchEvent(event);
        }
      }
      return true;
    });

This is a very simple bubbling but it should works fine and could be improved in more PR eventually.
I created a branch, maybe I could push it and create a PR?
Thanks!

TypeScript version

Hi

In the process of "typing" your event-target polyfill I came across the following issues:

The attempt to delete these fields produces errors as they are read-only. So are they in plain JS. Does this mean these lines could be safely removed from the code?

        delete event.currentTarget;
        delete event.target;

The last line of the addEventListener definition produces an error, as listeners is only declared locally in the for-loop. Into which context could the declaration for listeners be moved without breaking the code?

listeners.push({target: this, listener: listener, options: options});

Thanks for any suggestions
dsheyp

Unable to extend EventTarget

Unable to extend EventTarget in NodeJS and Jest

const EventTarget = require('@ungap/event-target')

class L extends EventTarget {}

const listener = new L();

const event = new CustomEvent('a');

listener.addEventListener('a', console.log);
listener.dispatchEvent(event);

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.