Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
add second argument to event listener callback
Browse files Browse the repository at this point in the history
  • Loading branch information
0x8890 committed Sep 26, 2016
1 parent c0596d8 commit ffecb3c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


### 1.4.3 (2016-09-26)
- Polish: add second argument to `bindEvents` event listener functions.


### 1.4.2 (2016-09-21)
- Fix: `animate` helper should use MutationObserver to detect DOM insertion. This fixes insert animations in Firefox.

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ var change = chain(
// automatically removing event listeners, even if the element is still
// in the DOM. The optional second argument is `useCapture`.
bindEvents({
click: function (event) {
// The first argument is the DOM event, second is the path to the data.
click: function (event, path) {
event.target.classList.toggle('alternate')
}
}),
Expand Down
14 changes: 10 additions & 4 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@ module.exports = {
},

bindEvents: function (events, useCapture) {
var listeners = {}

if (useCapture === void 0) useCapture = false

return function (node, value, previousValue) {
return function (node, value, previousValue, path) {
var key

if (value == null)
for (key in events)
node.removeEventListener(key, events[key], useCapture)
node.removeEventListener(key, listeners[key], useCapture)
else if (previousValue == null)
for (key in events)
node.addEventListener(key, events[key], useCapture)
for (key in events) {
listeners[key] = function eventListener (event) {
return events[key](event, path)
}
node.addEventListener(key, listeners[key], useCapture)
}
}
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "simulacra",
"description": "Reactive data binding for web applications.",
"version": "1.4.2",
"version": "1.4.3",
"license": "MIT",
"author": {
"email": "0x8890@airmail.cc",
Expand Down
2 changes: 1 addition & 1 deletion website/helper.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}
}

setTimeout(setData, Math.random() * 500 + 250)
setTimeout(setData, Math.random() * 250 + 250)
}
}()
</script>

0 comments on commit ffecb3c

Please sign in to comment.