MCPcopy Create free account
hub / github.com/OneNoteDev/WebClipper / subscribe

Method subscribe

src/scripts/communicator/smartValue.ts:17–32  ·  view source on GitHub ↗
(func: (newValue: T) => void, options: Options = {})

Source from the content-addressed store, hash-verified

15 }
16
17 public subscribe(func: (newValue: T) => void, options: Options = {}) {
18 // Setup the defaults if they weren't specified
19 if (options.times === undefined) {
20 options.times = Infinity;
21 }
22 if (options.callOnSubscribe === undefined) {
23 options.callOnSubscribe = true;
24 }
25
26 if (options.callOnSubscribe) {
27 func(this.t);
28 }
29 if (options.times > 0) {
30 this.subscriptions.push({ func: func, times: options.times });
31 }
32 }
33
34 public unsubscribe(func: (newValue: T) => void) {
35 for (let i = 0; i < this.subscriptions.length; i++) {

Callers 7

testsMethod · 0.95
initializeSmartValuesMethod · 0.80

Calls 2

funcFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected