add YEvent
This commit is contained in:
		
							parent
							
								
									b7defc32e8
								
							
						
					
					
						commit
						0310500c4e
					
				
							
								
								
									
										27
									
								
								src/Util/YEvent.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/Util/YEvent.js
									
									
									
									
									
										Normal 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
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user