fix event.path by using event.currentTarget

This commit is contained in:
Kevin Jahns
2017-11-08 17:31:12 -08:00
parent a08624c04e
commit 4f55e8c655
5 changed files with 67 additions and 27 deletions

View File

@@ -2,32 +2,27 @@
export default class YEvent {
constructor (target) {
this.target = target
this._path = null
this.currentTarget = target
}
get path () {
if (this._path !== null) {
return this._path
} else {
const path = []
let type = this.target
const y = type._y
while (type._parent !== y) {
let parent = type._parent
if (type._parentSub !== null) {
path.push(type._parentSub)
} else {
// parent is array-ish
for (let [i, child] of parent) {
if (child === type) {
path.push(i)
break
}
const path = []
let type = this.target
const y = type._y
while (type._parent !== this._currentTarget && type._parent !== y) {
let parent = type._parent
if (type._parentSub !== null) {
path.push(type._parentSub)
} else {
// parent is array-ish
for (let [i, child] of parent) {
if (child === type) {
path.push(i)
break
}
}
type = parent
}
this._path = path
return path
type = parent
}
return path
}
}