MCPcopy Create free account
hub / github.com/codemix/graph / subscribe

Method subscribe

packages/y-graph-storage/src/YGraph.ts:57–76  ·  view source on GitHub ↗

* Subscribe to changes to the graph. * @param observer The observer to subscribe to. * @returns A function to unsubscribe from the changes.

(observer: Observer<YGraphChange>)

Source from the content-addressed store, hash-verified

55 * @returns A function to unsubscribe from the changes.
56 */
57 public subscribe(observer: Observer<YGraphChange>) {
58 const subscribers = this.#subscribers;
59 subscribers.add(observer);
60 if (this.#subscription === undefined) {
61 this.#subscription = createGraphObserver(this).subscribe({
62 next(value) {
63 for (const subscriber of subscribers) {
64 subscriber.next?.(value);
65 }
66 },
67 });
68 }
69 return () => {
70 subscribers.delete(observer);
71 if (subscribers.size === 0) {
72 this.#subscription?.unsubscribe();
73 this.#subscription = undefined;
74 }
75 };
76 }
77
78 /**
79 * Create a live query.

Callers 2

subscribeMethod · 0.45

Calls 2

createGraphObserverFunction · 0.85
addMethod · 0.65

Tested by

no test coverage detected