@real1ty-obsidian-plugins/utils 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/async/change-notifier.d.ts +13 -0
- package/dist/async/change-notifier.d.ts.map +1 -0
- package/dist/async/change-notifier.js +26 -0
- package/dist/async/change-notifier.js.map +1 -0
- package/dist/async/debounced-notifier.d.ts +26 -0
- package/dist/async/debounced-notifier.d.ts.map +1 -0
- package/dist/async/debounced-notifier.js +50 -0
- package/dist/async/debounced-notifier.js.map +1 -0
- package/dist/async/index.d.ts +2 -0
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +2 -0
- package/dist/async/index.js.map +1 -1
- package/package.json +1 -1
- package/src/async/change-notifier.ts +26 -0
- package/src/async/debounced-notifier.ts +56 -0
- package/src/async/index.ts +2 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Subscription } from "rxjs";
|
|
2
|
+
/**
|
|
3
|
+
* Base class that provides observable change notification capabilities.
|
|
4
|
+
* Eliminates boilerplate for classes that need to notify observers of state changes.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class ChangeNotifier {
|
|
7
|
+
private changeSubject;
|
|
8
|
+
readonly changes$: import("rxjs").Observable<void>;
|
|
9
|
+
protected notifyChange(): void;
|
|
10
|
+
subscribe(observer: () => void): Subscription;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=change-notifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-notifier.d.ts","sourceRoot":"","sources":["../../src/async/change-notifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAElD;;;GAGG;AACH,8BAAsB,cAAc;IACnC,OAAO,CAAC,aAAa,CAAuB;IAC5C,SAAgB,QAAQ,kCAAqC;IAE7D,SAAS,CAAC,YAAY,IAAI,IAAI;IAQ9B,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,YAAY;IAI7C,OAAO,IAAI,IAAI;CAGf"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Subject } from "rxjs";
|
|
2
|
+
/**
|
|
3
|
+
* Base class that provides observable change notification capabilities.
|
|
4
|
+
* Eliminates boilerplate for classes that need to notify observers of state changes.
|
|
5
|
+
*/
|
|
6
|
+
export class ChangeNotifier {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.changeSubject = new Subject();
|
|
9
|
+
this.changes$ = this.changeSubject.asObservable();
|
|
10
|
+
}
|
|
11
|
+
notifyChange() {
|
|
12
|
+
try {
|
|
13
|
+
this.changeSubject.next();
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.error("Error notifying change:", error);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
subscribe(observer) {
|
|
20
|
+
return this.changes$.subscribe(observer);
|
|
21
|
+
}
|
|
22
|
+
destroy() {
|
|
23
|
+
this.changeSubject.complete();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=change-notifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-notifier.js","sourceRoot":"","sources":["../../src/async/change-notifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAqB,MAAM,MAAM,CAAC;AAElD;;;GAGG;AACH,MAAM,OAAgB,cAAc;IAApC;QACS,kBAAa,GAAG,IAAI,OAAO,EAAQ,CAAC;QAC5B,aAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;IAiB9D,CAAC;IAfU,YAAY;QACrB,IAAI,CAAC;YACJ,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;IAED,SAAS,CAAC,QAAoB;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;QACN,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACD","sourcesContent":["import { Subject, type Subscription } from \"rxjs\";\n\n/**\n * Base class that provides observable change notification capabilities.\n * Eliminates boilerplate for classes that need to notify observers of state changes.\n */\nexport abstract class ChangeNotifier {\n\tprivate changeSubject = new Subject<void>();\n\tpublic readonly changes$ = this.changeSubject.asObservable();\n\n\tprotected notifyChange(): void {\n\t\ttry {\n\t\t\tthis.changeSubject.next();\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Error notifying change:\", error);\n\t\t}\n\t}\n\n\tsubscribe(observer: () => void): Subscription {\n\t\treturn this.changes$.subscribe(observer);\n\t}\n\n\tdestroy(): void {\n\t\tthis.changeSubject.complete();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ChangeNotifier } from "./change-notifier";
|
|
2
|
+
/**
|
|
3
|
+
* Extends ChangeNotifier with debounced notification capabilities.
|
|
4
|
+
* Prevents excessive notifications when many changes happen rapidly by batching them.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class DebouncedNotifier extends ChangeNotifier {
|
|
7
|
+
private refreshTimeout;
|
|
8
|
+
private readonly debounceMs;
|
|
9
|
+
constructor(debounceMs?: number);
|
|
10
|
+
/**
|
|
11
|
+
* Schedules a debounced refresh to prevent excessive notifications.
|
|
12
|
+
* Batches rapid changes into a single notification after inactivity period.
|
|
13
|
+
*/
|
|
14
|
+
protected scheduleRefresh(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Flushes any pending debounced refresh and immediately notifies subscribers.
|
|
17
|
+
* Used after batch operations to ensure immediate updates without waiting for debounce.
|
|
18
|
+
*/
|
|
19
|
+
protected flushPendingRefresh(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if there is a pending debounced refresh scheduled.
|
|
22
|
+
*/
|
|
23
|
+
protected hasPendingRefresh(): boolean;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=debounced-notifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounced-notifier.d.ts","sourceRoot":"","sources":["../../src/async/debounced-notifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,8BAAsB,iBAAkB,SAAQ,cAAc;IAC7D,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,UAAU,SAAM;IAK5B;;;OAGG;IACH,SAAS,CAAC,eAAe,IAAI,IAAI;IAUjC;;;OAGG;IACH,SAAS,CAAC,mBAAmB,IAAI,IAAI;IAQrC;;OAEG;IACH,SAAS,CAAC,iBAAiB,IAAI,OAAO;IAI7B,OAAO,IAAI,IAAI;CAOxB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ChangeNotifier } from "./change-notifier";
|
|
2
|
+
/**
|
|
3
|
+
* Extends ChangeNotifier with debounced notification capabilities.
|
|
4
|
+
* Prevents excessive notifications when many changes happen rapidly by batching them.
|
|
5
|
+
*/
|
|
6
|
+
export class DebouncedNotifier extends ChangeNotifier {
|
|
7
|
+
constructor(debounceMs = 150) {
|
|
8
|
+
super();
|
|
9
|
+
this.refreshTimeout = null;
|
|
10
|
+
this.debounceMs = debounceMs;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Schedules a debounced refresh to prevent excessive notifications.
|
|
14
|
+
* Batches rapid changes into a single notification after inactivity period.
|
|
15
|
+
*/
|
|
16
|
+
scheduleRefresh() {
|
|
17
|
+
if (this.refreshTimeout) {
|
|
18
|
+
clearTimeout(this.refreshTimeout);
|
|
19
|
+
}
|
|
20
|
+
this.refreshTimeout = setTimeout(() => {
|
|
21
|
+
this.notifyChange();
|
|
22
|
+
this.refreshTimeout = null;
|
|
23
|
+
}, this.debounceMs);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Flushes any pending debounced refresh and immediately notifies subscribers.
|
|
27
|
+
* Used after batch operations to ensure immediate updates without waiting for debounce.
|
|
28
|
+
*/
|
|
29
|
+
flushPendingRefresh() {
|
|
30
|
+
if (this.refreshTimeout) {
|
|
31
|
+
clearTimeout(this.refreshTimeout);
|
|
32
|
+
this.refreshTimeout = null;
|
|
33
|
+
this.notifyChange();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Checks if there is a pending debounced refresh scheduled.
|
|
38
|
+
*/
|
|
39
|
+
hasPendingRefresh() {
|
|
40
|
+
return this.refreshTimeout !== null;
|
|
41
|
+
}
|
|
42
|
+
destroy() {
|
|
43
|
+
if (this.refreshTimeout) {
|
|
44
|
+
clearTimeout(this.refreshTimeout);
|
|
45
|
+
this.refreshTimeout = null;
|
|
46
|
+
}
|
|
47
|
+
super.destroy();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=debounced-notifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounced-notifier.js","sourceRoot":"","sources":["../../src/async/debounced-notifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAgB,iBAAkB,SAAQ,cAAc;IAI7D,YAAY,UAAU,GAAG,GAAG;QAC3B,KAAK,EAAE,CAAC;QAJD,mBAAc,GAAyC,IAAI,CAAC;QAKnE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACO,eAAe;QACxB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,GAAG,EAAE;YACrC,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC5B,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACrB,CAAC;IAED;;;OAGG;IACO,mBAAmB;QAC5B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,IAAI,CAAC,YAAY,EAAE,CAAC;QACrB,CAAC;IACF,CAAC;IAED;;OAEG;IACO,iBAAiB;QAC1B,OAAO,IAAI,CAAC,cAAc,KAAK,IAAI,CAAC;IACrC,CAAC;IAEQ,OAAO;QACf,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC5B,CAAC;QACD,KAAK,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;CACD","sourcesContent":["import { ChangeNotifier } from \"./change-notifier\";\n\n/**\n * Extends ChangeNotifier with debounced notification capabilities.\n * Prevents excessive notifications when many changes happen rapidly by batching them.\n */\nexport abstract class DebouncedNotifier extends ChangeNotifier {\n\tprivate refreshTimeout: ReturnType<typeof setTimeout> | null = null;\n\tprivate readonly debounceMs: number;\n\n\tconstructor(debounceMs = 150) {\n\t\tsuper();\n\t\tthis.debounceMs = debounceMs;\n\t}\n\n\t/**\n\t * Schedules a debounced refresh to prevent excessive notifications.\n\t * Batches rapid changes into a single notification after inactivity period.\n\t */\n\tprotected scheduleRefresh(): void {\n\t\tif (this.refreshTimeout) {\n\t\t\tclearTimeout(this.refreshTimeout);\n\t\t}\n\t\tthis.refreshTimeout = setTimeout(() => {\n\t\t\tthis.notifyChange();\n\t\t\tthis.refreshTimeout = null;\n\t\t}, this.debounceMs);\n\t}\n\n\t/**\n\t * Flushes any pending debounced refresh and immediately notifies subscribers.\n\t * Used after batch operations to ensure immediate updates without waiting for debounce.\n\t */\n\tprotected flushPendingRefresh(): void {\n\t\tif (this.refreshTimeout) {\n\t\t\tclearTimeout(this.refreshTimeout);\n\t\t\tthis.refreshTimeout = null;\n\t\t\tthis.notifyChange();\n\t\t}\n\t}\n\n\t/**\n\t * Checks if there is a pending debounced refresh scheduled.\n\t */\n\tprotected hasPendingRefresh(): boolean {\n\t\treturn this.refreshTimeout !== null;\n\t}\n\n\toverride destroy(): void {\n\t\tif (this.refreshTimeout) {\n\t\t\tclearTimeout(this.refreshTimeout);\n\t\t\tthis.refreshTimeout = null;\n\t\t}\n\t\tsuper.destroy();\n\t}\n}\n"]}
|
package/dist/async/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|
package/dist/async/index.js
CHANGED
package/dist/async/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./async\";\nexport * from \"./batch-operations\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC","sourcesContent":["export * from \"./async\";\nexport * from \"./batch-operations\";\nexport * from \"./change-notifier\";\nexport * from \"./debounced-notifier\";\n"]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Subject, type Subscription } from "rxjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base class that provides observable change notification capabilities.
|
|
5
|
+
* Eliminates boilerplate for classes that need to notify observers of state changes.
|
|
6
|
+
*/
|
|
7
|
+
export abstract class ChangeNotifier {
|
|
8
|
+
private changeSubject = new Subject<void>();
|
|
9
|
+
public readonly changes$ = this.changeSubject.asObservable();
|
|
10
|
+
|
|
11
|
+
protected notifyChange(): void {
|
|
12
|
+
try {
|
|
13
|
+
this.changeSubject.next();
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error("Error notifying change:", error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
subscribe(observer: () => void): Subscription {
|
|
20
|
+
return this.changes$.subscribe(observer);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
destroy(): void {
|
|
24
|
+
this.changeSubject.complete();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ChangeNotifier } from "./change-notifier";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extends ChangeNotifier with debounced notification capabilities.
|
|
5
|
+
* Prevents excessive notifications when many changes happen rapidly by batching them.
|
|
6
|
+
*/
|
|
7
|
+
export abstract class DebouncedNotifier extends ChangeNotifier {
|
|
8
|
+
private refreshTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
9
|
+
private readonly debounceMs: number;
|
|
10
|
+
|
|
11
|
+
constructor(debounceMs = 150) {
|
|
12
|
+
super();
|
|
13
|
+
this.debounceMs = debounceMs;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Schedules a debounced refresh to prevent excessive notifications.
|
|
18
|
+
* Batches rapid changes into a single notification after inactivity period.
|
|
19
|
+
*/
|
|
20
|
+
protected scheduleRefresh(): void {
|
|
21
|
+
if (this.refreshTimeout) {
|
|
22
|
+
clearTimeout(this.refreshTimeout);
|
|
23
|
+
}
|
|
24
|
+
this.refreshTimeout = setTimeout(() => {
|
|
25
|
+
this.notifyChange();
|
|
26
|
+
this.refreshTimeout = null;
|
|
27
|
+
}, this.debounceMs);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Flushes any pending debounced refresh and immediately notifies subscribers.
|
|
32
|
+
* Used after batch operations to ensure immediate updates without waiting for debounce.
|
|
33
|
+
*/
|
|
34
|
+
protected flushPendingRefresh(): void {
|
|
35
|
+
if (this.refreshTimeout) {
|
|
36
|
+
clearTimeout(this.refreshTimeout);
|
|
37
|
+
this.refreshTimeout = null;
|
|
38
|
+
this.notifyChange();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Checks if there is a pending debounced refresh scheduled.
|
|
44
|
+
*/
|
|
45
|
+
protected hasPendingRefresh(): boolean {
|
|
46
|
+
return this.refreshTimeout !== null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override destroy(): void {
|
|
50
|
+
if (this.refreshTimeout) {
|
|
51
|
+
clearTimeout(this.refreshTimeout);
|
|
52
|
+
this.refreshTimeout = null;
|
|
53
|
+
}
|
|
54
|
+
super.destroy();
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/async/index.ts
CHANGED