joist-core 2.3.0-next.13 → 2.3.0-next.14
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.
|
@@ -8,19 +8,24 @@ import { PropertyT } from "./hasProperty";
|
|
|
8
8
|
* a `ReactiveField`, but when the value needs to be calculated from SQL because
|
|
9
9
|
* it would be too expensive to calculate in-memory.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* Its hint is split in two: the `loadHint` names data that is both reacted-to *and*
|
|
12
|
+
* loaded into memory (and passed to `fn`), while the `reactiveHint` names data that is
|
|
13
|
+
* only reacted-to (its changes recompute the value) but is left in the database rather
|
|
14
|
+
* than pulled into memory. The `fn` lambda re-runs when data referred to by either hint
|
|
15
|
+
* changes, but only the `loadHint`'s data is populated.
|
|
14
16
|
*/
|
|
15
|
-
export declare function hasAsyncReactiveField<T extends Entity, const H1 extends ReactiveHint<T>, const H2 extends ReactiveHint<T>, V>(
|
|
17
|
+
export declare function hasAsyncReactiveField<T extends Entity, const H1 extends ReactiveHint<T>, const H2 extends ReactiveHint<T>, V>(loadHint: H1, reactiveHint: H2, fn: (entity: Reacted<T, H1>) => Promise<V>): ReactiveField<T, V>;
|
|
16
18
|
export declare class AsyncReactiveFieldImpl<T extends Entity, H1 extends ReactiveHint<T>, H2 extends ReactiveHint<T>, V> extends AbstractPropertyImpl<T> implements ReactiveField<T, V> {
|
|
17
19
|
#private;
|
|
18
20
|
fieldName: keyof T & string;
|
|
19
|
-
paramHint: H1;
|
|
20
|
-
dbHint: H2;
|
|
21
21
|
private fn;
|
|
22
|
-
constructor(entity: T, fieldName: keyof T & string,
|
|
23
|
-
/**
|
|
22
|
+
constructor(entity: T, fieldName: keyof T & string, loadHint: H1, reactiveHint: H2, fn: (entity: Reacted<T, H1>) => Promise<V>);
|
|
23
|
+
/**
|
|
24
|
+
* Our combined load + reactive-only hint, so that we react to changes within both.
|
|
25
|
+
*
|
|
26
|
+
* The `loadHint` half is populated into memory (and passed to `fn`); the `reactiveHint`
|
|
27
|
+
* half only triggers recalculation, so its data stays in the database.
|
|
28
|
+
*/
|
|
24
29
|
get reactiveHint(): ReactiveHint<any>;
|
|
25
30
|
load(opts?: {
|
|
26
31
|
forceReload?: boolean;
|
|
@@ -17,41 +17,44 @@ const hasProperty_1 = require("./hasProperty");
|
|
|
17
17
|
* a `ReactiveField`, but when the value needs to be calculated from SQL because
|
|
18
18
|
* it would be too expensive to calculate in-memory.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Its hint is split in two: the `loadHint` names data that is both reacted-to *and*
|
|
21
|
+
* loaded into memory (and passed to `fn`), while the `reactiveHint` names data that is
|
|
22
|
+
* only reacted-to (its changes recompute the value) but is left in the database rather
|
|
23
|
+
* than pulled into memory. The `fn` lambda re-runs when data referred to by either hint
|
|
24
|
+
* changes, but only the `loadHint`'s data is populated.
|
|
23
25
|
*/
|
|
24
|
-
function hasAsyncReactiveField(
|
|
26
|
+
function hasAsyncReactiveField(loadHint, reactiveHint, fn) {
|
|
25
27
|
return (0, newEntity_1.lazyField)((entity, fieldName) => {
|
|
26
|
-
return new AsyncReactiveFieldImpl(entity, fieldName,
|
|
28
|
+
return new AsyncReactiveFieldImpl(entity, fieldName, loadHint, reactiveHint, fn);
|
|
27
29
|
});
|
|
28
30
|
}
|
|
29
31
|
class AsyncReactiveFieldImpl extends AbstractPropertyImpl_1.AbstractPropertyImpl {
|
|
30
32
|
fieldName;
|
|
31
|
-
paramHint;
|
|
32
|
-
dbHint;
|
|
33
33
|
fn;
|
|
34
|
-
#
|
|
35
|
-
#
|
|
34
|
+
#loadHint;
|
|
35
|
+
#reactiveHint;
|
|
36
36
|
#loadPromise;
|
|
37
37
|
#loaded;
|
|
38
38
|
#useFactoryValue = false;
|
|
39
|
-
constructor(entity, fieldName,
|
|
39
|
+
constructor(entity, fieldName, loadHint, reactiveHint, fn) {
|
|
40
40
|
super(entity);
|
|
41
41
|
this.fieldName = fieldName;
|
|
42
|
-
this.paramHint = paramHint;
|
|
43
|
-
this.dbHint = dbHint;
|
|
44
42
|
this.fn = fn;
|
|
45
|
-
this.#
|
|
46
|
-
this.#
|
|
43
|
+
this.#loadHint = loadHint;
|
|
44
|
+
this.#reactiveHint = reactiveHint;
|
|
47
45
|
this.#loaded = false;
|
|
48
46
|
}
|
|
49
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Our combined load + reactive-only hint, so that we react to changes within both.
|
|
49
|
+
*
|
|
50
|
+
* The `loadHint` half is populated into memory (and passed to `fn`); the `reactiveHint`
|
|
51
|
+
* half only triggers recalculation, so its data stays in the database.
|
|
52
|
+
*/
|
|
50
53
|
get reactiveHint() {
|
|
51
54
|
// We do this in a getter (instead of the constructor) b/c it might be a little expensive,
|
|
52
55
|
// and I'm pretty sure this is only called on boot, when hooking up the reactivity.
|
|
53
|
-
const hint = (0, index_1.deepNormalizeHint)(this.#
|
|
54
|
-
(0, utils_1.mergeNormalizedHints)(hint, (0, index_1.deepNormalizeHint)(this.#
|
|
56
|
+
const hint = (0, index_1.deepNormalizeHint)(this.#loadHint);
|
|
57
|
+
(0, utils_1.mergeNormalizedHints)(hint, (0, index_1.deepNormalizeHint)(this.#reactiveHint));
|
|
55
58
|
return hint;
|
|
56
59
|
}
|
|
57
60
|
load(opts) {
|
|
@@ -103,9 +106,9 @@ class AsyncReactiveFieldImpl extends AbstractPropertyImpl_1.AbstractPropertyImpl
|
|
|
103
106
|
return hintLoaded;
|
|
104
107
|
}
|
|
105
108
|
get loadHint() {
|
|
106
|
-
// Only convert the
|
|
109
|
+
// Only convert the loadHint, so we don't pull the reactiveHint-referenced data into memory
|
|
107
110
|
const meta = (0, EntityMetadata_1.getMetadata)(this.entity);
|
|
108
|
-
return (meta.config.__data.cachedReactiveLoadHints[this.fieldName] ??= (0, reactiveHints_1.convertToLoadHint)(meta, this.#
|
|
111
|
+
return (meta.config.__data.cachedReactiveLoadHints[this.fieldName] ??= (0, reactiveHints_1.convertToLoadHint)(meta, this.#loadHint));
|
|
109
112
|
}
|
|
110
113
|
setFactoryValue(newValue) {
|
|
111
114
|
this.#useFactoryValue = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncReactiveField.js","sourceRoot":"","sources":["../../src/relations/AsyncReactiveField.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"AsyncReactiveField.js","sourceRoot":"","sources":["../../src/relations/AsyncReactiveField.ts"],"names":[],"mappings":";;;AAqBA,sDASC;AA0GD,oDAEC;AAGD,gEAEC;AA9ID,sDAAgD;AAChD,sCAA2D;AAC3D,oCAAsE;AACtE,4CAAyC;AACzC,oDAA4E;AAC5E,oCAAgD;AAChD,iEAA8D;AAC9D,+CAA0C;AAE1C;;;;;;;;;;GAUG;AACH,SAAgB,qBAAqB,CAKnC,QAAY,EAAE,YAAgB,EAAE,EAA0C;IAC1E,OAAO,IAAA,qBAAS,EAAC,CAAC,MAAS,EAAE,SAAS,EAAE,EAAE;QACxC,OAAO,IAAI,sBAAsB,CAAC,MAAM,EAAE,SAA6B,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC;IACvG,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAa,sBACX,SAAQ,2CAAuB;IAWtB;IAGC;IAXD,SAAS,CAAK;IACd,aAAa,CAAK;IAC3B,YAAY,CAAM;IAClB,OAAO,CAAU;IACjB,gBAAgB,GAAG,KAAK,CAAC;IAEzB,YACE,MAAS,EACF,SAA2B,EAClC,QAAY,EACZ,YAAgB,EACR,EAA0C;QAElD,KAAK,CAAC,MAAM,CAAC,CAAC;QALP,cAAS,GAAT,SAAS,CAAkB;QAG1B,OAAE,GAAF,EAAE,CAAwC;QAGlD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,OAAO,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B,oBAAoB,CAAC,KAAU;IAC7C,OAAO,KAAK,YAAY,sBAAsB,CAAC;AACjD,CAAC;AAED,4FAA4F;AAC5F,SAAgB,0BAA0B,CAAC,KAAU;IACnD,OAAO,oBAAoB,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC;AACvD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "joist-core",
|
|
3
|
-
"version": "2.3.0-next.
|
|
3
|
+
"version": "2.3.0-next.14",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"build"
|
|
21
21
|
],
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"joist-utils": "2.3.0-next.
|
|
23
|
+
"joist-utils": "2.3.0-next.14"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"ansis": "^4.3.1",
|