| 7 | } |
| 8 | |
| 9 | export class AttributeObserver implements ElementObserverDelegate { |
| 10 | attributeName: string |
| 11 | private delegate: AttributeObserverDelegate |
| 12 | |
| 13 | private elementObserver: ElementObserver |
| 14 | |
| 15 | constructor(element: Element, attributeName: string, delegate: AttributeObserverDelegate) { |
| 16 | this.attributeName = attributeName |
| 17 | this.delegate = delegate |
| 18 | |
| 19 | this.elementObserver = new ElementObserver(element, this) |
| 20 | } |
| 21 | |
| 22 | get element(): Element { |
| 23 | return this.elementObserver.element |
| 24 | } |
| 25 | |
| 26 | get selector(): string { |
| 27 | return `[${this.attributeName}]` |
| 28 | } |
| 29 | |
| 30 | start() { |
| 31 | this.elementObserver.start() |
| 32 | } |
| 33 | |
| 34 | pause(callback: () => void) { |
| 35 | this.elementObserver.pause(callback) |
| 36 | } |
| 37 | |
| 38 | stop() { |
| 39 | this.elementObserver.stop() |
| 40 | } |
| 41 | |
| 42 | refresh() { |
| 43 | this.elementObserver.refresh() |
| 44 | } |
| 45 | |
| 46 | get started(): boolean { |
| 47 | return this.elementObserver.started |
| 48 | } |
| 49 | |
| 50 | // Element observer delegate |
| 51 | |
| 52 | matchElement(element: Element): boolean { |
| 53 | return element.hasAttribute(this.attributeName) |
| 54 | } |
| 55 | |
| 56 | matchElementsInTree(tree: Element): Element[] { |
| 57 | const match = this.matchElement(tree) ? [tree] : [] |
| 58 | const matches = Array.from(tree.querySelectorAll(this.selector)) |
| 59 | return match.concat(matches) |
| 60 | } |
| 61 | |
| 62 | elementMatched(element: Element) { |
| 63 | if (this.delegate.elementMatchedAttribute) { |
| 64 | this.delegate.elementMatchedAttribute(element, this.attributeName) |
| 65 | } |
| 66 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…