@dra2020/baseclient 1.0.73 → 1.0.77
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/baseclient.js +42 -49
- package/dist/baseclient.js.map +1 -1
- package/dist/dataflow/dataflow.d.ts +20 -17
- package/lib/dataflow/dataflow.ts +54 -51
- package/package.json +1 -1
package/dist/baseclient.js
CHANGED
|
@@ -1016,79 +1016,72 @@ __exportStar(__webpack_require__(/*! ./dataflow */ "./lib/dataflow/dataflow.ts")
|
|
|
1016
1016
|
// DataFlow: mechanism for setting up a data-flow dependency graph that gets computed on demand.
|
|
1017
1017
|
//
|
|
1018
1018
|
// Semantics are these:
|
|
1019
|
-
// 1. The simplest "atomic" DataFlow object just has an id()
|
|
1020
|
-
// equivalence when determining if any dependents need to be recomputed.
|
|
1021
|
-
// for something that just creates a new whole object when recomputed. In other cases, id() might represent a
|
|
1022
|
-
// hash or changestamp/timestamp that is distinct from the value(). The value may or may not be "ready" as well.
|
|
1023
|
-
// If the value is not "ready", no dependents can be computed.
|
|
1019
|
+
// 1. The simplest "atomic" DataFlow object just has an id(). The id() is used to check for exact
|
|
1020
|
+
// equivalence when determining if any dependents need to be recomputed.
|
|
1024
1021
|
// 2. A DataFlow object can record that it "uses" another DataFlow object. If it does, it can use a set of helper
|
|
1025
|
-
// routines to track the state of its dependents. When its dependents are
|
|
1026
|
-
//
|
|
1022
|
+
// routines to track the state of its dependents. When its dependents are "stale" (have changed) the computation
|
|
1023
|
+
// needs to be run.
|
|
1027
1024
|
//
|
|
1028
1025
|
//
|
|
1029
1026
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1030
|
-
exports.
|
|
1027
|
+
exports.DataFlowStamp = exports.DataFlowCallback = exports.DataFlow = void 0;
|
|
1031
1028
|
class DataFlow {
|
|
1032
1029
|
constructor() {
|
|
1033
|
-
this.usesList =
|
|
1034
|
-
this.uniquename = 1;
|
|
1030
|
+
this.usesList = [];
|
|
1035
1031
|
}
|
|
1036
1032
|
// override in subclass
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
uses(df, name) {
|
|
1041
|
-
if (!name)
|
|
1042
|
-
name = `_df_${this.uniquename++}`;
|
|
1043
|
-
this.usesList[name] = { name: name, df: df };
|
|
1044
|
-
}
|
|
1045
|
-
find(name) {
|
|
1046
|
-
let ui = this.usesList[name];
|
|
1047
|
-
return ui ? ui.df : undefined;
|
|
1048
|
-
}
|
|
1049
|
-
findValue(name) {
|
|
1050
|
-
let df = this.find(name);
|
|
1051
|
-
return df ? df.value() : undefined;
|
|
1033
|
+
dfid() { return null; }
|
|
1034
|
+
// override in subclass
|
|
1035
|
+
compute() {
|
|
1052
1036
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
Object.values(this.usesList).forEach((ui) => { if (!ui.df.ready())
|
|
1056
|
-
isready = false; });
|
|
1057
|
-
return isready;
|
|
1037
|
+
uses(df, name) {
|
|
1038
|
+
this.usesList.push({ name: name, df: df });
|
|
1058
1039
|
}
|
|
1059
1040
|
usesStale() {
|
|
1060
1041
|
let isstale = false;
|
|
1061
|
-
|
|
1062
|
-
|
|
1042
|
+
this.usesList.forEach(ui => {
|
|
1043
|
+
ui.wasstale = ui.id !== ui.df.dfid();
|
|
1044
|
+
if (ui.wasstale)
|
|
1045
|
+
isstale = true;
|
|
1046
|
+
});
|
|
1063
1047
|
return isstale;
|
|
1064
1048
|
}
|
|
1049
|
+
wasStale(name) {
|
|
1050
|
+
let ui = this.usesList.find((ui) => ui.name === name);
|
|
1051
|
+
return ui != null && ui.wasstale;
|
|
1052
|
+
}
|
|
1065
1053
|
usesRemember() {
|
|
1066
|
-
|
|
1054
|
+
this.usesList.forEach(ui => { ui.id = ui.df.dfid(); });
|
|
1055
|
+
}
|
|
1056
|
+
ifcompute() {
|
|
1057
|
+
if (this.usesStale()) {
|
|
1058
|
+
this.usesRemember();
|
|
1059
|
+
this.compute();
|
|
1060
|
+
}
|
|
1067
1061
|
}
|
|
1068
1062
|
}
|
|
1069
1063
|
exports.DataFlow = DataFlow;
|
|
1070
|
-
// Takes callback that,
|
|
1071
|
-
|
|
1064
|
+
// Takes callback that, eventually, returns non-null. The return value is both the value and the id.
|
|
1065
|
+
// Once the value returns non-null, the callback is never called again.
|
|
1066
|
+
class DataFlowCallback extends DataFlow {
|
|
1072
1067
|
constructor(cb) {
|
|
1073
1068
|
super();
|
|
1074
1069
|
this._cb = cb;
|
|
1075
1070
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
}
|
|
1086
|
-
return !!this._value;
|
|
1071
|
+
dfid() { if (!this._value)
|
|
1072
|
+
this._value = this._cb(); return this._value; }
|
|
1073
|
+
}
|
|
1074
|
+
exports.DataFlowCallback = DataFlowCallback;
|
|
1075
|
+
// Simple helper that maintains a simple monotonically increasing stamp
|
|
1076
|
+
class DataFlowStamp extends DataFlow {
|
|
1077
|
+
constructor() {
|
|
1078
|
+
super();
|
|
1079
|
+
this._stamp = 0;
|
|
1087
1080
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1081
|
+
dfid() { return this._stamp; }
|
|
1082
|
+
stamp() { this._stamp++; }
|
|
1090
1083
|
}
|
|
1091
|
-
exports.
|
|
1084
|
+
exports.DataFlowStamp = DataFlowStamp;
|
|
1092
1085
|
|
|
1093
1086
|
|
|
1094
1087
|
/***/ }),
|