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

Class BindingObserver

src/core/binding_observer.ts:13–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13export class BindingObserver implements ValueListObserverDelegate<Action> {
14 readonly context: Context
15 private delegate: BindingObserverDelegate
16 private valueListObserver?: ValueListObserver<Action>
17 private bindingsByAction: Map<Action, Binding>
18
19 constructor(context: Context, delegate: BindingObserverDelegate) {
20 this.context = context
21 this.delegate = delegate
22 this.bindingsByAction = new Map()
23 }
24
25 start() {
26 if (!this.valueListObserver) {
27 this.valueListObserver = new ValueListObserver(this.element, this.actionAttribute, this)
28 this.valueListObserver.start()
29 }
30 }
31
32 stop() {
33 if (this.valueListObserver) {
34 this.valueListObserver.stop()
35 delete this.valueListObserver
36 this.disconnectAllActions()
37 }
38 }
39
40 get element() {
41 return this.context.element
42 }
43
44 get identifier() {
45 return this.context.identifier
46 }
47
48 get actionAttribute() {
49 return this.schema.actionAttribute
50 }
51
52 get schema(): Schema {
53 return this.context.schema
54 }
55
56 get bindings(): Binding[] {
57 return Array.from(this.bindingsByAction.values())
58 }
59
60 private connectAction(action: Action) {
61 const binding = new Binding(this.context, action)
62 this.bindingsByAction.set(action, binding)
63 this.delegate.bindingConnected(binding)
64 }
65
66 private disconnectAction(action: Action) {
67 const binding = this.bindingsByAction.get(action)
68 if (binding) {
69 this.bindingsByAction.delete(action)
70 this.delegate.bindingDisconnected(binding)

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…