add YEvent

This commit is contained in:
Kevin Jahns 2017-11-07 20:34:44 -08:00
parent b7defc32e8
commit 0310500c4e

27
src/Util/YEvent.js Normal file
View File

@ -0,0 +1,27 @@
export default class YEvent {
constructor (target) {
this.target = target
}
get path () {
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
}
}
}
type = parent
}
return path
}
}