necolas / delegate.js Goto Github PK
View Code? Open in Web Editor NEWDOM event delegation component
License: MIT License
DOM event delegation component
License: MIT License
See:
necolas/matches.js@6ac4a28
Related chai issue:
chaijs/chai#175
Could we simplify this lib by relying on your closest
implementation? It seems the whole of this function can be replaced with a call to closest?
So, this line could be replaced as so:
if (e.delegateTarget = closest(e.target, selector, elem)) {
Aside: I intended to submit PR for this. Couldn't get npm to install as-is (needed to update Karma), and then I couldn't get tests to run
Should probably clean up and not leave the wrapped function attached to the callback once it's been removed.
This change would involve creating a registry to keep track of the element-delegate-callback relationship. It would avoid a callback for a given event type being unbound for all delegators, rather than just the delegator you're interested in.
An object that implements EventListener interface (https://developer.mozilla.org/en-US/docs/Web/API/EventListener) has a handleEvent
method. e.g.:
var obj = {
log : function(e) {
console.log("event", e.type, "happened on", e.target);
},
handleEvent : function(e) {
this.log(e);
}
};
Notice that the this
value in handleEvent
is bound to the object itself. As obj
implements the EventListener interface, it can be registered directly as an event listener:
document.addEventListener("click", obj, false);
It would be great if the EventListener interface was respected by delegate.js and worked as one would expect:
delegate(body).on("click", ".some-selector", obj);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.