shelving 1.85.0 → 1.86.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/package.json +8 -8
- package/sequence/DeferredSequence.d.ts +5 -3
- package/sequence/DeferredSequence.js +15 -11
- package/state/State.d.ts +3 -3
- package/state/State.js +8 -17
- package/util/class.d.ts +1 -1
- package/util/class.js +1 -1
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"state-management",
|
|
12
12
|
"query-builder"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.86.0",
|
|
15
15
|
"repository": "https://github.com/dhoulb/shelving",
|
|
16
16
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
17
17
|
"license": "0BSD",
|
|
@@ -64,21 +64,21 @@
|
|
|
64
64
|
"build:jest": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config=jest.config.build.cjs"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@google-cloud/firestore": "^
|
|
68
|
-
"@types/jest": "^
|
|
67
|
+
"@google-cloud/firestore": "^6.4.0",
|
|
68
|
+
"@types/jest": "^29.2.0",
|
|
69
69
|
"@types/react": "^18.0.21",
|
|
70
70
|
"@types/react-dom": "^18.0.4",
|
|
71
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
72
|
-
"@typescript-eslint/parser": "^5.
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
|
72
|
+
"@typescript-eslint/parser": "^5.40.0",
|
|
73
73
|
"dpdm": "^3.9.0",
|
|
74
|
-
"esbuild": "^0.15.
|
|
74
|
+
"esbuild": "^0.15.11",
|
|
75
75
|
"esbuild-jest": "^0.5.0",
|
|
76
76
|
"eslint": "^8.25.0",
|
|
77
77
|
"eslint-config-prettier": "^8.5.0",
|
|
78
78
|
"eslint-plugin-import": "^2.26.0",
|
|
79
79
|
"eslint-plugin-prettier": "^4.0.0",
|
|
80
|
-
"firebase": "^9.
|
|
81
|
-
"jest": "^
|
|
80
|
+
"firebase": "^9.12.1",
|
|
81
|
+
"jest": "^29.2.1",
|
|
82
82
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
83
83
|
"prettier": "^2.6.2",
|
|
84
84
|
"react": "^18.1.0",
|
|
@@ -21,12 +21,14 @@ export declare class DeferredSequence<T = void, R = void> extends AbstractSequen
|
|
|
21
21
|
private _nextReason;
|
|
22
22
|
/** Fulfill the current deferred by resolving or rejecting it. */
|
|
23
23
|
private readonly _fulfill;
|
|
24
|
-
/** Resolve the current deferred from a sequence of values. */
|
|
25
|
-
resolveSequence(sequence: AsyncIterable<T>): AsyncIterable<T>;
|
|
26
24
|
next(): Promise<IteratorResult<T, R>>;
|
|
27
25
|
then<X = T, Y = never>(onNext?: (v: T) => X | PromiseLike<X>, onError?: (r: unknown) => Y | PromiseLike<Y>): Promise<X | Y>;
|
|
28
26
|
catch<Y>(onError: (r: unknown) => Y | PromiseLike<Y>): Promise<T | Y>;
|
|
29
27
|
finally(onFinally: () => void): Promise<T>;
|
|
28
|
+
/** Resolve the current deferred from a sequence of values. */
|
|
29
|
+
through(sequence: AsyncIterable<T>): AsyncIterable<T>;
|
|
30
|
+
/** Pull values from a source sequence until the returned stop function is called. */
|
|
31
|
+
from(source: AsyncIterable<T>, onError?: Handler): Stop;
|
|
30
32
|
/** Subscrbe to the value of the sequence with a callback until the returned stop function is called. */
|
|
31
|
-
|
|
33
|
+
to(onNext: Dispatch<[T]>, onError?: Handler): Stop;
|
|
32
34
|
}
|
|
@@ -28,10 +28,10 @@ export class DeferredSequence extends AbstractSequence {
|
|
|
28
28
|
/** Fulfill the current deferred by resolving or rejecting it. */
|
|
29
29
|
this._fulfill = () => {
|
|
30
30
|
const { _deferred, _nextReason, _nextValue } = this;
|
|
31
|
+
this._deferred = undefined;
|
|
32
|
+
this._nextReason = _NOVALUE;
|
|
33
|
+
this._nextValue = _NOVALUE;
|
|
31
34
|
if (_deferred) {
|
|
32
|
-
this._deferred = undefined;
|
|
33
|
-
this._nextReason = _NOVALUE;
|
|
34
|
-
this._nextValue = _NOVALUE;
|
|
35
35
|
if (_nextReason !== _NOVALUE)
|
|
36
36
|
_deferred.reject(_nextReason);
|
|
37
37
|
else if (_nextValue !== _NOVALUE)
|
|
@@ -43,13 +43,6 @@ export class DeferredSequence extends AbstractSequence {
|
|
|
43
43
|
get value() {
|
|
44
44
|
return (this._deferred || (this._deferred = new Deferred()));
|
|
45
45
|
}
|
|
46
|
-
/** Resolve the current deferred from a sequence of values. */
|
|
47
|
-
async *resolveSequence(sequence) {
|
|
48
|
-
for await (const item of sequence) {
|
|
49
|
-
this.resolve(item);
|
|
50
|
-
yield item;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
46
|
// Implement `AsyncIterator`
|
|
54
47
|
async next() {
|
|
55
48
|
return { value: await this.value };
|
|
@@ -64,8 +57,19 @@ export class DeferredSequence extends AbstractSequence {
|
|
|
64
57
|
finally(onFinally) {
|
|
65
58
|
return this.value.finally(onFinally);
|
|
66
59
|
}
|
|
60
|
+
/** Resolve the current deferred from a sequence of values. */
|
|
61
|
+
async *through(sequence) {
|
|
62
|
+
for await (const item of sequence) {
|
|
63
|
+
this.resolve(item);
|
|
64
|
+
yield item;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Pull values from a source sequence until the returned stop function is called. */
|
|
68
|
+
from(source, onError) {
|
|
69
|
+
return runSequence(this.through(source), undefined, onError);
|
|
70
|
+
}
|
|
67
71
|
/** Subscrbe to the value of the sequence with a callback until the returned stop function is called. */
|
|
68
|
-
|
|
72
|
+
to(onNext, onError) {
|
|
69
73
|
return runSequence(this, onNext, onError);
|
|
70
74
|
}
|
|
71
75
|
}
|
package/state/State.d.ts
CHANGED
|
@@ -32,12 +32,12 @@ export declare class State<T> implements AsyncIterable<T> {
|
|
|
32
32
|
/** Set the value of the state. */
|
|
33
33
|
set(value: T): void;
|
|
34
34
|
/** Set the value of the state as values are pulled from a sequence. */
|
|
35
|
-
|
|
35
|
+
through(sequence: AsyncIterable<T>): AsyncIterable<T>;
|
|
36
36
|
/** Pull values from a source sequence until the returned stop function is called. */
|
|
37
37
|
from(source: AsyncIterable<T>, onError?: Handler): Stop;
|
|
38
38
|
/** Push values to another state or callback to this state until the returned stop function is called. */
|
|
39
|
-
to(target:
|
|
40
|
-
[Symbol.asyncIterator](): AsyncIterator<T
|
|
39
|
+
to(target: Dispatch<[T]>, onError?: Handler): Stop;
|
|
40
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
41
41
|
}
|
|
42
42
|
/** Is an unknown value a `State` instance. */
|
|
43
43
|
export declare const isState: <T extends AnyState>(v: unknown) => v is T;
|
package/state/State.js
CHANGED
|
@@ -45,7 +45,7 @@ export class State {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
/** Set the value of the state as values are pulled from a sequence. */
|
|
48
|
-
async *
|
|
48
|
+
async *through(sequence) {
|
|
49
49
|
for await (const value of sequence) {
|
|
50
50
|
this.set(value);
|
|
51
51
|
yield value;
|
|
@@ -53,28 +53,19 @@ export class State {
|
|
|
53
53
|
}
|
|
54
54
|
/** Pull values from a source sequence until the returned stop function is called. */
|
|
55
55
|
from(source, onError) {
|
|
56
|
-
return runSequence(this.
|
|
56
|
+
return runSequence(this.through(source), onError);
|
|
57
57
|
}
|
|
58
58
|
/** Push values to another state or callback to this state until the returned stop function is called. */
|
|
59
59
|
to(target, onError) {
|
|
60
|
-
|
|
61
|
-
return runSequence(target.setSequence(this), onError);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
return runSequence(this, target, onError);
|
|
65
|
-
}
|
|
60
|
+
return runSequence(this, target, onError);
|
|
66
61
|
}
|
|
67
62
|
// Implement `AsyncIterable`
|
|
68
63
|
// Issues the current value of the state first, then any subsequent values that are issued.
|
|
69
|
-
[Symbol.asyncIterator]() {
|
|
70
|
-
//
|
|
71
|
-
if (this.loading)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// But! If additional values are set synchronously, only the yield the final one. Use a new `DeferredSequence` to make sure this happens cleanly.
|
|
75
|
-
const deferred = new DeferredSequence();
|
|
76
|
-
deferred.resolve(this.value);
|
|
77
|
-
return deferred.resolveSequence(this.next)[Symbol.asyncIterator]();
|
|
64
|
+
async *[Symbol.asyncIterator]() {
|
|
65
|
+
await Promise.resolve(); // Introduce a slight delay, i.e. don't immediately yield `this.value` in case it is changed synchronously.
|
|
66
|
+
if (!this.loading)
|
|
67
|
+
yield this.value;
|
|
68
|
+
yield* this.next;
|
|
78
69
|
}
|
|
79
70
|
}
|
|
80
71
|
/** The `NOVALUE` symbol indicates no value has been received by a `State` instance. */
|
package/util/class.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare function cacheGetter<T>(target: Object, key: string, { get }: Typ
|
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* class MyClass {
|
|
34
|
-
*
|
|
34
|
+
* @setPrototype("myProp", "myValue!") readonly myProp!: string;
|
|
35
35
|
* }
|
|
36
36
|
*/
|
|
37
37
|
export declare function setPrototype<K extends PropertyKey, T>(key: K, value: T): (prototype: {
|
package/util/class.js
CHANGED
|
@@ -61,7 +61,7 @@ export function cacheGetter(target, key, { get }) {
|
|
|
61
61
|
*
|
|
62
62
|
* @example
|
|
63
63
|
* class MyClass {
|
|
64
|
-
*
|
|
64
|
+
* @setPrototype("myProp", "myValue!") readonly myProp!: string;
|
|
65
65
|
* }
|
|
66
66
|
*/
|
|
67
67
|
export function setPrototype(key, value) {
|