react-obsidian 1.3.0 → 1.4.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/src/observable/mediator/MediatorObservable.d.ts +2 -1
- package/dist/src/observable/mediator/MediatorObservable.d.ts.map +1 -1
- package/dist/src/observable/mediator/MediatorObservable.js +7 -0
- package/dist/src/observable/mediator/MediatorObservable.js.map +1 -1
- package/dist/src/observable/types.d.ts +1 -0
- package/dist/src/observable/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/observable/mediator/MediatorObservable.ts +9 -1
- package/src/observable/types.ts +3 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Observable } from '../Observable';
|
|
2
|
-
import { OnNext } from '../types';
|
|
2
|
+
import { Mapper, OnNext } from '../types';
|
|
3
3
|
export declare class MediatorObservable<T> extends Observable<T> {
|
|
4
|
+
mapSource<Source, Result extends T>(source: Observable<Source>, mapNext: Mapper<Source, Result>): this;
|
|
4
5
|
addSource<S>(source: Observable<S>, onNext: OnNext<S>): this;
|
|
5
6
|
}
|
|
6
7
|
//# sourceMappingURL=MediatorObservable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediatorObservable.d.ts","sourceRoot":"","sources":["../../../../src/observable/mediator/MediatorObservable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"MediatorObservable.d.ts","sourceRoot":"","sources":["../../../../src/observable/mediator/MediatorObservable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAE1C,qBAAa,kBAAkB,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACtD,SAAS,CAAC,MAAM,EAAE,MAAM,SAAS,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQ/F,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAOtD"}
|
|
@@ -3,6 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MediatorObservable = void 0;
|
|
4
4
|
const Observable_1 = require("../Observable");
|
|
5
5
|
class MediatorObservable extends Observable_1.Observable {
|
|
6
|
+
mapSource(source, mapNext) {
|
|
7
|
+
this.addSource(source, (next) => {
|
|
8
|
+
const mapped = mapNext(next, this.value);
|
|
9
|
+
this.value = mapped;
|
|
10
|
+
});
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
6
13
|
addSource(source, onNext) {
|
|
7
14
|
source.subscribe(onNext);
|
|
8
15
|
if (source.value !== undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediatorObservable.js","sourceRoot":"","sources":["../../../../src/observable/mediator/MediatorObservable.ts"],"names":[],"mappings":";;;AAAA,8CAA2C;AAG3C,MAAa,kBAAsB,SAAQ,uBAAa;IACtD,SAAS,CAAI,MAAqB,EAAE,MAAiB;QACnD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE;YAC9B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACtB;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"MediatorObservable.js","sourceRoot":"","sources":["../../../../src/observable/mediator/MediatorObservable.ts"],"names":[],"mappings":";;;AAAA,8CAA2C;AAG3C,MAAa,kBAAsB,SAAQ,uBAAa;IACtD,SAAS,CAA2B,MAA0B,EAAE,OAA+B;QAC7F,IAAI,CAAC,SAAS,CAAS,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACtC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,KAAe,CAAW,CAAC;YAC7D,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;QACtB,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,CAAI,MAAqB,EAAE,MAAiB;QACnD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE;YAC9B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SACtB;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAhBD,gDAgBC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type OnNext<T> = (value: T) => void | undefined;
|
|
2
|
+
export type Mapper<Other, Mine> = (next: Other, currentValue: Mine) => Mine extends void ? 'A map function must return a value. Check your map function and ensure it has a valid return statement.' : Mine;
|
|
2
3
|
export type Unsubscribe = () => void;
|
|
3
4
|
export interface Observable<T> {
|
|
4
5
|
value: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/observable/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,SAAS,CAAC;AACvD,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,KAAK,EAAE,CAAC,CAAC;IACT,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;CAC3C;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/observable/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,SAAS,CAAC;AACvD,MAAM,MAAM,MAAM,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,KAAK,IAAI,SAAS,IAAI,GACtF,yGAAyG,GACzG,IAAI,CAAC;AACP,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,KAAK,EAAE,CAAC,CAAC;IACT,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;CAC3C;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { Observable } from '../Observable';
|
|
2
|
-
import { OnNext } from '../types';
|
|
2
|
+
import { Mapper, OnNext } from '../types';
|
|
3
3
|
|
|
4
4
|
export class MediatorObservable<T> extends Observable<T> {
|
|
5
|
+
mapSource<Source, Result extends T>(source: Observable<Source>, mapNext: Mapper<Source, Result>) {
|
|
6
|
+
this.addSource<Source>(source, (next) => {
|
|
7
|
+
const mapped = mapNext(next, this.value as Result) as Result;
|
|
8
|
+
this.value = mapped;
|
|
9
|
+
});
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
addSource<S>(source: Observable<S>, onNext: OnNext<S>) {
|
|
6
14
|
source.subscribe(onNext);
|
|
7
15
|
if (source.value !== undefined) {
|
package/src/observable/types.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export type OnNext<T> = (value: T) => void | undefined; // OnNext callbacks should never return a value
|
|
2
|
+
export type Mapper<Other, Mine> = (next: Other, currentValue: Mine) => Mine extends void ?
|
|
3
|
+
'A map function must return a value. Check your map function and ensure it has a valid return statement.' :
|
|
4
|
+
Mine;
|
|
2
5
|
export type Unsubscribe = () => void;
|
|
3
6
|
|
|
4
7
|
export interface Observable<T> {
|