Skip to content

Commit

Permalink
Merge pull request #18 from deepak1556/vdom_patch
Browse files Browse the repository at this point in the history
using evstore for vdom compatibility
  • Loading branch information
Raynos committed Feb 5, 2015
2 parents 82a21dc + 69cd9a9 commit 3a181ea
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
20 changes: 10 additions & 10 deletions add-event.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
var DataSet = require("data-set")
var EvStore = require("ev-store")

module.exports = addEvent

function addEvent(target, type, handler) {
var ds = DataSet(target)
var events = ds[type]
var events = EvStore(target)
var event = events[type]

if (!events) {
ds[type] = handler
} else if (Array.isArray(events)) {
if (events.indexOf(handler) === -1) {
events.push(handler)
if (!event) {
events[type] = handler
} else if (Array.isArray(event)) {
if (event.indexOf(handler) === -1) {
event.push(handler)
}
} else if (events !== handler) {
ds[type] = [events, handler]
} else if (event !== handler) {
events[type] = [event, handler]
}
}
8 changes: 4 additions & 4 deletions dom-delegator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var globalDocument = require("global/document")
var DataSet = require("data-set")
var EvStore = require("ev-store")
var createStore = require("weakmap-shim/create-store")

var addEvent = require("./add-event.js")
Expand Down Expand Up @@ -149,10 +149,10 @@ function getListener(target, type) {
return null
}

var ds = DataSet(target)
var events = EvStore(target)
// fetch list of handler fns for this event
var handler = ds[type]
var allHandler = ds.event
var handler = events[type]
var allHandler = events.event

if (!handler && !allHandler) {
return getListener(target.parentNode, type)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"cuid": "^1.2.4",
"data-set": "^3.1.0",
"ev-store": "^7.0.0",
"global": "^4.2.1",
"individual": "^2.0.0",
"inherits": "^2.0.1",
Expand Down
18 changes: 9 additions & 9 deletions remove-event.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var DataSet = require("data-set")
var EvStore = require("ev-store")

module.exports = removeEvent

function removeEvent(target, type, handler) {
var ds = DataSet(target)
var events = ds[type]
var events = EvStore(target)
var event = events[type]

if (!events) {
if (!event) {
return
} else if (Array.isArray(events)) {
var index = events.indexOf(handler)
} else if (Array.isArray(event)) {
var index = event.indexOf(handler)
if (index !== -1) {
events.splice(index, 1)
event.splice(index, 1)
}
} else if (events === handler) {
ds[type] = null
} else if (event === handler) {
events[type] = null
}
}
14 changes: 7 additions & 7 deletions test/dom-data-events.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var test = require("tape")
var setImmediate = require("timers").setImmediate
var document = require("global/document")
var DataSet = require("data-set")
var EvStore = require("ev-store")

var h = require("./lib/h.js")
var createEvent = require("./lib/create-event.js")

var Delegator = require("../index.js")

test("setting event listeners with data-set directly", function (assert) {
test("setting event listeners with ev-store directly", function (assert) {
var elem = h("div")
document.body.appendChild(elem)

Delegator()
var values = []

DataSet(elem).click = function (ev) {
EvStore(elem).click = function (ev) {
values.push(ev)
}

Expand Down Expand Up @@ -54,8 +54,8 @@ test("setting an id'd event handler", function (assert) {
id: d.id
}

DataSet(elem).click = handler
DataSet(elem).event = eventHandler
EvStore(elem).click = handler
EvStore(elem).event = eventHandler

var ev = createEvent("click")
elem.dispatchEvent(ev)
Expand All @@ -80,7 +80,7 @@ test("setting data-event to array", function (assert) {
Delegator()
var values = []

DataSet(elem).click = [function (ev) {
EvStore(elem).click = [function (ev) {
values.push(ev)
}, function (ev) {
values.push(ev)
Expand Down Expand Up @@ -120,7 +120,7 @@ test("data-event to array of id'd handlers", function (assert) {
id: d.id
}

DataSet(elem).event = [submitHandler, changeHandler]
EvStore(elem).event = [submitHandler, changeHandler]

var ev = createEvent("click")
elem.dispatchEvent(ev)
Expand Down

0 comments on commit 3a181ea

Please sign in to comment.