@dra2020/baseclient 1.0.72 → 1.0.76

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.
@@ -0,0 +1 @@
1
+ export * from './dataflow';
@@ -0,0 +1,24 @@
1
+ interface UseItem {
2
+ name?: string;
3
+ df: DataFlow;
4
+ id?: any;
5
+ wasstale?: boolean;
6
+ }
7
+ export declare class DataFlow {
8
+ usesList: UseItem[];
9
+ constructor();
10
+ id(): any;
11
+ uses(df: DataFlow, name?: string): void;
12
+ usesStale(): boolean;
13
+ wasStale(name: string): boolean;
14
+ usesRemember(): void;
15
+ ifcompute(): void;
16
+ compute(): void;
17
+ }
18
+ export declare class DataFlowCallback extends DataFlow {
19
+ _value: any;
20
+ _cb: () => any;
21
+ constructor(cb: () => any);
22
+ id(): any;
23
+ }
24
+ export {};
package/lib/all/all.ts CHANGED
@@ -25,3 +25,5 @@ import * as CSV from '../csv/all';
25
25
  export { CSV };
26
26
  import * as Colors from '../colors/colors';
27
27
  export { Colors };
28
+ import * as DataFlow from '../dataflow/all';
29
+ export { DataFlow }
@@ -0,0 +1 @@
1
+ export * from './dataflow';
@@ -0,0 +1,87 @@
1
+ //
2
+ // DataFlow: mechanism for setting up a data-flow dependency graph that gets computed on demand.
3
+ //
4
+ // Semantics are these:
5
+ // 1. The simplest "atomic" DataFlow object just has an id(). The id() is used to check for exact
6
+ // equivalence when determining if any dependents need to be recomputed.
7
+ // 2. A DataFlow object can record that it "uses" another DataFlow object. If it does, it can use a set of helper
8
+ // routines to track the state of its dependents. When its dependents are "stale" (have changed) the computation
9
+ // needs to be run.
10
+ //
11
+ //
12
+
13
+ interface UseItem
14
+ {
15
+ name?: string;
16
+ df: DataFlow,
17
+ id?: any,
18
+ wasstale?: boolean,
19
+ }
20
+
21
+ export class DataFlow
22
+ {
23
+ usesList: UseItem[];
24
+
25
+ constructor()
26
+ {
27
+ this.usesList = [];
28
+ }
29
+
30
+ // override in subclass
31
+ id(): any { return null }
32
+
33
+ uses(df: DataFlow, name?: string): void
34
+ {
35
+ this.usesList.push({ name: name, df: df });
36
+ }
37
+
38
+ usesStale(): boolean
39
+ {
40
+ let isstale = false;
41
+ this.usesList.forEach(ui => {
42
+ ui.wasstale = ui.id !== ui.df.id();
43
+ if (ui.wasstale) isstale = true;
44
+ });
45
+ return isstale;
46
+ }
47
+
48
+ wasStale(name: string): boolean
49
+ {
50
+ let ui: UseItem = this.usesList.find((ui: UseItem) => ui.name === name);
51
+ return ui != null && ui.wasstale;
52
+ }
53
+
54
+ usesRemember(): void
55
+ {
56
+ this.usesList.forEach(ui => { ui.id = ui.df.id() });
57
+ }
58
+
59
+ ifcompute(): void
60
+ {
61
+ if (this.usesStale())
62
+ {
63
+ this.usesRemember();
64
+ this.compute();
65
+ }
66
+ }
67
+
68
+ compute(): void
69
+ {
70
+ }
71
+ }
72
+
73
+ // Takes callback that, eventually, returns non-null. The return value is both the value and the id.
74
+ // Once the value returns non-null, the callback is never called again.
75
+ export class DataFlowCallback extends DataFlow
76
+ {
77
+ _value: any;
78
+ _cb: () => any;
79
+
80
+ constructor(cb: () => any)
81
+ {
82
+ super();
83
+ this._cb = cb;
84
+ }
85
+
86
+ id(): any { if (!this._value) this._value = this._cb(); return this._value }
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.72",
3
+ "version": "1.0.76",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",