react-obsidian 0.0.45 → 0.0.46
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/src/observable/MediatorObservable.d.ts +2 -10
- package/dist/src/observable/MediatorObservable.d.ts.map +1 -1
- package/dist/src/observable/MediatorObservable.js +3 -33
- package/dist/src/observable/MediatorObservable.js.map +1 -1
- package/package.json +1 -1
- package/src/observable/MediatorObservable.ts +3 -49
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { Observable } from './Observable';
|
|
2
|
-
import { OnNext
|
|
3
|
-
export declare class MediatorObservable<T>
|
|
4
|
-
private subscribers;
|
|
5
|
-
private currentValue;
|
|
6
|
-
private sources;
|
|
7
|
-
constructor(initialValue?: T);
|
|
2
|
+
import { OnNext } from './types';
|
|
3
|
+
export declare class MediatorObservable<T> extends Observable<T> {
|
|
8
4
|
addSource<S>(source: Observable<S>, onNext: OnNext<S>): MediatorObservable<T>;
|
|
9
|
-
get value(): T;
|
|
10
|
-
set value(value: T);
|
|
11
|
-
subscribe(onNext: OnNext<T>): Unsubscribe;
|
|
12
|
-
private subscribeToAllSources;
|
|
13
5
|
}
|
|
14
6
|
//# sourceMappingURL=MediatorObservable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediatorObservable.d.ts","sourceRoot":"","sources":["../../../src/observable/MediatorObservable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"MediatorObservable.d.ts","sourceRoot":"","sources":["../../../src/observable/MediatorObservable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,qBAAa,kBAAkB,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACtD,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC;CAI9E"}
|
|
@@ -1,42 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MediatorObservable = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.subscribers = new Set();
|
|
7
|
-
this.sources = [];
|
|
8
|
-
this.currentValue = initialValue;
|
|
9
|
-
}
|
|
4
|
+
const Observable_1 = require("./Observable");
|
|
5
|
+
class MediatorObservable extends Observable_1.Observable {
|
|
10
6
|
addSource(source, onNext) {
|
|
11
|
-
|
|
7
|
+
source.subscribe(onNext);
|
|
12
8
|
return this;
|
|
13
9
|
}
|
|
14
|
-
get value() {
|
|
15
|
-
return this.currentValue;
|
|
16
|
-
}
|
|
17
|
-
set value(value) {
|
|
18
|
-
this.currentValue = value;
|
|
19
|
-
this.subscribers.forEach((subscriber) => subscriber(value));
|
|
20
|
-
}
|
|
21
|
-
subscribe(onNext) {
|
|
22
|
-
if (this.subscribers.has(onNext)) {
|
|
23
|
-
throw new Error('Subscriber already subscribed');
|
|
24
|
-
}
|
|
25
|
-
this.subscribers.add(onNext);
|
|
26
|
-
this.subscribeToAllSources();
|
|
27
|
-
return () => {
|
|
28
|
-
this.subscribers.delete(onNext);
|
|
29
|
-
this.sources.forEach(({ unsubscribe }) => unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe());
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
subscribeToAllSources() {
|
|
33
|
-
this.sources.forEach(({ source, onNext }, index) => {
|
|
34
|
-
const unsubscribe = source.subscribe((value) => {
|
|
35
|
-
onNext(value);
|
|
36
|
-
});
|
|
37
|
-
this.sources[index].unsubscribe = unsubscribe;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
10
|
}
|
|
41
11
|
exports.MediatorObservable = MediatorObservable;
|
|
42
12
|
//# sourceMappingURL=MediatorObservable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediatorObservable.js","sourceRoot":"","sources":["../../../src/observable/MediatorObservable.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"MediatorObservable.js","sourceRoot":"","sources":["../../../src/observable/MediatorObservable.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAG1C,MAAa,kBAAsB,SAAQ,uBAAa;IACtD,SAAS,CAAI,MAAqB,EAAE,MAAiB;QACnD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AALD,gDAKC"}
|
package/package.json
CHANGED
|
@@ -1,55 +1,9 @@
|
|
|
1
1
|
import { Observable } from './Observable';
|
|
2
|
-
import { OnNext
|
|
3
|
-
|
|
4
|
-
type Source<T> = {
|
|
5
|
-
source: Observable<T>;
|
|
6
|
-
onNext: OnNext<T>;
|
|
7
|
-
unsubscribe?: Unsubscribe;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export class MediatorObservable<T> implements IObservable<T> {
|
|
11
|
-
private subscribers: Set<OnNext<T>> = new Set();
|
|
12
|
-
private currentValue!: T;
|
|
13
|
-
private sources: Source<any>[] = [];
|
|
14
|
-
|
|
15
|
-
constructor(initialValue?: T) {
|
|
16
|
-
this.currentValue = initialValue as T;
|
|
17
|
-
}
|
|
2
|
+
import { OnNext } from './types';
|
|
18
3
|
|
|
4
|
+
export class MediatorObservable<T> extends Observable<T> {
|
|
19
5
|
addSource<S>(source: Observable<S>, onNext: OnNext<S>): MediatorObservable<T> {
|
|
20
|
-
|
|
6
|
+
source.subscribe(onNext);
|
|
21
7
|
return this;
|
|
22
8
|
}
|
|
23
|
-
|
|
24
|
-
public get value(): T {
|
|
25
|
-
return this.currentValue;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public set value(value: T) {
|
|
29
|
-
this.currentValue = value;
|
|
30
|
-
this.subscribers.forEach((subscriber) => subscriber(value));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
subscribe(onNext: OnNext<T>): Unsubscribe {
|
|
34
|
-
if (this.subscribers.has(onNext)) {
|
|
35
|
-
throw new Error('Subscriber already subscribed');
|
|
36
|
-
}
|
|
37
|
-
this.subscribers.add(onNext);
|
|
38
|
-
|
|
39
|
-
this.subscribeToAllSources();
|
|
40
|
-
|
|
41
|
-
return () => {
|
|
42
|
-
this.subscribers.delete(onNext);
|
|
43
|
-
this.sources.forEach(({ unsubscribe }) => unsubscribe?.());
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private subscribeToAllSources() {
|
|
48
|
-
this.sources.forEach(({ source, onNext }, index) => {
|
|
49
|
-
const unsubscribe = source.subscribe((value) => {
|
|
50
|
-
onNext(value);
|
|
51
|
-
});
|
|
52
|
-
this.sources[index].unsubscribe = unsubscribe;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
9
|
}
|