react-obsidian 0.0.34 → 0.0.36
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/index.d.ts +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/observable/{ObservableMediator.d.ts → MediatorObservable.d.ts} +3 -3
- package/dist/src/observable/{ObservableMediator.d.ts.map → MediatorObservable.d.ts.map} +1 -1
- package/dist/src/observable/{ObservableMediator.js → MediatorObservable.js} +10 -10
- package/dist/src/observable/{ObservableMediator.js.map → MediatorObservable.js.map} +1 -1
- package/dist/src/observable/useObserver.d.ts +1 -1
- package/dist/src/observable/useObserver.d.ts.map +1 -1
- package/dist/src/observable/useObserver.js +1 -2
- package/dist/src/observable/useObserver.js.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +1 -1
- package/src/observable/{ObservableMediator.ts → MediatorObservable.ts} +2 -2
- package/src/observable/useObserver.ts +2 -3
package/dist/src/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export { injectComponent } from './injectors/components/InjectComponent';
|
|
|
16
16
|
export { injectHook, injectHookWithArguments } from './injectors/hooks/InjectHook';
|
|
17
17
|
export { useObserver } from './observable/useObserver';
|
|
18
18
|
export { Observable } from './observable/Observable';
|
|
19
|
-
export {
|
|
19
|
+
export { MediatorObservable } from './observable/MediatorObservable';
|
|
20
20
|
export { OnNext, Unsubscribe } from './observable/types';
|
|
21
21
|
export { testKit } from '../testkit';
|
|
22
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.testKit = exports.
|
|
20
|
+
exports.testKit = exports.MediatorObservable = exports.Observable = exports.useObserver = exports.injectHookWithArguments = exports.injectHook = exports.injectComponent = exports.Obsidian = exports.GraphMiddleware = exports.LifecycleBound = exports.LazyInject = exports.Inject = exports.Injectable = exports.Provides = exports.ObjectGraph = exports.Singleton = exports.Graph = void 0;
|
|
21
21
|
var Obsidian_1 = __importDefault(require("./Obsidian"));
|
|
22
22
|
__exportStar(require("./types"), exports);
|
|
23
23
|
var Graph_1 = require("./decorators/Graph");
|
|
@@ -48,8 +48,8 @@ var useObserver_1 = require("./observable/useObserver");
|
|
|
48
48
|
Object.defineProperty(exports, "useObserver", { enumerable: true, get: function () { return useObserver_1.useObserver; } });
|
|
49
49
|
var Observable_1 = require("./observable/Observable");
|
|
50
50
|
Object.defineProperty(exports, "Observable", { enumerable: true, get: function () { return Observable_1.Observable; } });
|
|
51
|
-
var
|
|
52
|
-
Object.defineProperty(exports, "
|
|
51
|
+
var MediatorObservable_1 = require("./observable/MediatorObservable");
|
|
52
|
+
Object.defineProperty(exports, "MediatorObservable", { enumerable: true, get: function () { return MediatorObservable_1.MediatorObservable; } });
|
|
53
53
|
var testkit_1 = require("../testkit");
|
|
54
54
|
Object.defineProperty(exports, "testKit", { enumerable: true, get: function () { return testkit_1.testKit; } });
|
|
55
55
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Observable } from './Observable';
|
|
2
2
|
import { OnNext, Unsubscribe, Observable as IObservable } from './types';
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class MediatorObservable<T> implements IObservable<T> {
|
|
4
4
|
private subscribers;
|
|
5
5
|
private currentValue;
|
|
6
6
|
private sources;
|
|
7
7
|
constructor(initialValue?: T);
|
|
8
|
-
addSource<S>(source: Observable<S>, onNext: OnNext<S>):
|
|
8
|
+
addSource<S>(source: Observable<S>, onNext: OnNext<S>): MediatorObservable<T>;
|
|
9
9
|
get value(): T;
|
|
10
10
|
set value(value: T);
|
|
11
11
|
subscribe(onNext: OnNext<T>): Unsubscribe;
|
|
12
12
|
private subscribeToAllSources;
|
|
13
13
|
}
|
|
14
|
-
//# sourceMappingURL=
|
|
14
|
+
//# sourceMappingURL=MediatorObservable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
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,WAAW,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AAQzE,qBAAa,kBAAkB,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAC1D,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,OAAO,CAAqB;gBAExB,YAAY,CAAC,EAAE,CAAC;IAI5B,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC;IAK7E,IAAW,KAAK,IAAI,CAAC,CAEpB;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,CAAC,EAGxB;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW;IAczC,OAAO,CAAC,qBAAqB;CAQ9B"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
function
|
|
3
|
+
exports.MediatorObservable = void 0;
|
|
4
|
+
var MediatorObservable = /** @class */ (function () {
|
|
5
|
+
function MediatorObservable(initialValue) {
|
|
6
6
|
this.subscribers = new Set();
|
|
7
7
|
this.sources = [];
|
|
8
8
|
this.currentValue = initialValue;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
MediatorObservable.prototype.addSource = function (source, onNext) {
|
|
11
11
|
this.sources.push({ source: source, onNext: onNext });
|
|
12
12
|
return this;
|
|
13
13
|
};
|
|
14
|
-
Object.defineProperty(
|
|
14
|
+
Object.defineProperty(MediatorObservable.prototype, "value", {
|
|
15
15
|
get: function () {
|
|
16
16
|
return this.currentValue;
|
|
17
17
|
},
|
|
@@ -22,7 +22,7 @@ var ObservableMediator = /** @class */ (function () {
|
|
|
22
22
|
enumerable: false,
|
|
23
23
|
configurable: true
|
|
24
24
|
});
|
|
25
|
-
|
|
25
|
+
MediatorObservable.prototype.subscribe = function (onNext) {
|
|
26
26
|
var _this = this;
|
|
27
27
|
if (this.subscribers.has(onNext)) {
|
|
28
28
|
throw new Error('Subscriber already subscribed');
|
|
@@ -37,7 +37,7 @@ var ObservableMediator = /** @class */ (function () {
|
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
|
-
|
|
40
|
+
MediatorObservable.prototype.subscribeToAllSources = function () {
|
|
41
41
|
var _this = this;
|
|
42
42
|
this.sources.forEach(function (_a, index) {
|
|
43
43
|
var source = _a.source, onNext = _a.onNext;
|
|
@@ -47,7 +47,7 @@ var ObservableMediator = /** @class */ (function () {
|
|
|
47
47
|
_this.sources[index].unsubscribe = unsubscribe;
|
|
48
48
|
});
|
|
49
49
|
};
|
|
50
|
-
return
|
|
50
|
+
return MediatorObservable;
|
|
51
51
|
}());
|
|
52
|
-
exports.
|
|
53
|
-
//# sourceMappingURL=
|
|
52
|
+
exports.MediatorObservable = MediatorObservable;
|
|
53
|
+
//# sourceMappingURL=MediatorObservable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"MediatorObservable.js","sourceRoot":"","sources":["../../../src/observable/MediatorObservable.ts"],"names":[],"mappings":";;;AASA;IAKE,4BAAY,YAAgB;QAJpB,gBAAW,GAAmB,IAAI,GAAG,EAAE,CAAC;QAExC,YAAO,GAAkB,EAAE,CAAC;QAGlC,IAAI,CA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AAK,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;YACH,KAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,WAAW,GAAG,WAAW,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC;IACH,yBAAC;AAAD,CAAC,AA7CD,IA6CC;AA7CY,gDAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObserver.d.ts","sourceRoot":"","sources":["../../../src/observable/useObserver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useObserver.d.ts","sourceRoot":"","sources":["../../../src/observable/useObserver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,wBAAgB,WAAW,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,CAWhF"}
|
|
@@ -6,8 +6,7 @@ var react_1 = require("react");
|
|
|
6
6
|
function useObserver(observable) {
|
|
7
7
|
var _a = (0, react_1.useState)(observable.value), value = _a[0], setValue = _a[1];
|
|
8
8
|
var onNext = (0, react_1.useCallback)(function (next) {
|
|
9
|
-
|
|
10
|
-
observable.value = value;
|
|
9
|
+
observable.value = next;
|
|
11
10
|
}, [observable]);
|
|
12
11
|
(0, react_1.useEffect)(function () {
|
|
13
12
|
return observable.subscribe(setValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObserver.js","sourceRoot":"","sources":["../../../src/observable/useObserver.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,+BAAyD;AAGzD,SAAgB,WAAW,CAAI,UAAyB;IAChD,IAAA,KAAoB,IAAA,gBAAQ,EAAC,UAAU,CAAC,KAAK,CAAC,EAA7C,KAAK,QAAA,EAAE,QAAQ,QAA8B,CAAC;IACrD,IAAM,MAAM,GAAG,IAAA,mBAAW,EAAC,UAAC,IAAO;QACjC,
|
|
1
|
+
{"version":3,"file":"useObserver.js","sourceRoot":"","sources":["../../../src/observable/useObserver.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,+BAAyD;AAGzD,SAAgB,WAAW,CAAI,UAAyB;IAChD,IAAA,KAAoB,IAAA,gBAAQ,EAAC,UAAU,CAAC,KAAK,CAAC,EAA7C,KAAK,QAAA,EAAE,QAAQ,QAA8B,CAAC;IACrD,IAAM,MAAM,GAAG,IAAA,mBAAW,EAAC,UAAC,IAAO;QACjC,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC;IAC1B,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,IAAA,iBAAS,EAAC;QACR,OAAO,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACzB,CAAC;AAXD,kCAWC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-obsidian",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
4
4
|
"description": "Dependency injection framework for React and React Native applications",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepack": "npm run lint && tsc --project tsconfig.prod.json",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"lodash": "*"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@babel/core": "7.
|
|
25
|
-
"@babel/plugin-proposal-decorators": "7.
|
|
26
|
-
"@babel/preset-env": "7.
|
|
27
|
-
"@babel/preset-react": "7.
|
|
28
|
-
"@babel/preset-typescript": "7.
|
|
29
|
-
"@babel/types": "7.
|
|
24
|
+
"@babel/core": "7.20.x",
|
|
25
|
+
"@babel/plugin-proposal-decorators": "7.18.x",
|
|
26
|
+
"@babel/preset-env": "7.20.x",
|
|
27
|
+
"@babel/preset-react": "7.18.x",
|
|
28
|
+
"@babel/preset-typescript": "7.18.x",
|
|
29
|
+
"@babel/types": "7.20.x",
|
|
30
30
|
"@johanblumenberg/ts-mockito": "1.x.x",
|
|
31
31
|
"@testing-library/react": "^12.1.2",
|
|
32
32
|
"@testing-library/react-hooks": "^7.0.2",
|
package/src/index.ts
CHANGED
|
@@ -21,7 +21,7 @@ export { injectHook, injectHookWithArguments } from './injectors/hooks/InjectHoo
|
|
|
21
21
|
|
|
22
22
|
export { useObserver } from './observable/useObserver';
|
|
23
23
|
export { Observable } from './observable/Observable';
|
|
24
|
-
export {
|
|
24
|
+
export { MediatorObservable } from './observable/MediatorObservable';
|
|
25
25
|
export { OnNext, Unsubscribe } from './observable/types';
|
|
26
26
|
|
|
27
27
|
export { testKit } from '../testkit';
|
|
@@ -7,7 +7,7 @@ type Source<T> = {
|
|
|
7
7
|
unsubscribe?: Unsubscribe;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export class
|
|
10
|
+
export class MediatorObservable<T> implements IObservable<T> {
|
|
11
11
|
private subscribers: Set<OnNext<T>> = new Set();
|
|
12
12
|
private currentValue!: T;
|
|
13
13
|
private sources: Source<any>[] = [];
|
|
@@ -16,7 +16,7 @@ export class ObservableMediator<T> implements IObservable<T> {
|
|
|
16
16
|
this.currentValue = initialValue as T;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
addSource<S>(source: Observable<S>, onNext: OnNext<S>):
|
|
19
|
+
addSource<S>(source: Observable<S>, onNext: OnNext<S>): MediatorObservable<T> {
|
|
20
20
|
this.sources.push({ source, onNext });
|
|
21
21
|
return this;
|
|
22
22
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
2
|
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
-
import { Observable } from './
|
|
3
|
+
import { Observable } from './types';
|
|
4
4
|
|
|
5
5
|
export function useObserver<T>(observable: Observable<T>): [T, (next: T) => void] {
|
|
6
6
|
const [value, setValue] = useState(observable.value);
|
|
7
7
|
const onNext = useCallback((next: T) => {
|
|
8
|
-
|
|
9
|
-
observable.value = value;
|
|
8
|
+
observable.value = next;
|
|
10
9
|
}, [observable]);
|
|
11
10
|
|
|
12
11
|
useEffect(() => {
|