MCPcopy
hub / github.com/hotwired/stimulus / TokenListObserver

Class TokenListObserver

src/mutation-observers/token_list_observer.ts:16–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16export class TokenListObserver implements AttributeObserverDelegate {
17 private attributeObserver: AttributeObserver
18 private delegate: TokenListObserverDelegate
19 private tokensByElement: Multimap<Element, Token>
20
21 constructor(element: Element, attributeName: string, delegate: TokenListObserverDelegate) {
22 this.attributeObserver = new AttributeObserver(element, attributeName, this)
23 this.delegate = delegate
24 this.tokensByElement = new Multimap()
25 }
26
27 get started(): boolean {
28 return this.attributeObserver.started
29 }
30
31 start() {
32 this.attributeObserver.start()
33 }
34
35 pause(callback: () => void) {
36 this.attributeObserver.pause(callback)
37 }
38
39 stop() {
40 this.attributeObserver.stop()
41 }
42
43 refresh() {
44 this.attributeObserver.refresh()
45 }
46
47 get element(): Element {
48 return this.attributeObserver.element
49 }
50
51 get attributeName(): string {
52 return this.attributeObserver.attributeName
53 }
54
55 // Attribute observer delegate
56
57 elementMatchedAttribute(element: Element) {
58 this.tokensMatched(this.readTokensForElement(element))
59 }
60
61 elementAttributeValueChanged(element: Element) {
62 const [unmatchedTokens, matchedTokens] = this.refreshTokensForElement(element)
63 this.tokensUnmatched(unmatchedTokens)
64 this.tokensMatched(matchedTokens)
65 }
66
67 elementUnmatchedAttribute(element: Element) {
68 this.tokensUnmatched(this.tokensByElement.getValuesForKey(element))
69 }
70
71 private tokensMatched(tokens: Token[]) {
72 tokens.forEach((token) => this.tokenMatched(token))
73 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…