@dra2020/baseclient 1.0.73 → 1.0.75

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.
@@ -1,29 +1,22 @@
1
1
  interface UseItem {
2
- name: string;
3
2
  df: DataFlow;
4
3
  id?: any;
5
4
  }
6
5
  export declare class DataFlow {
7
- uniquename: number;
8
- usesList: {
9
- [name: string]: UseItem;
10
- };
6
+ usesList: UseItem[];
11
7
  constructor();
12
- ready(): boolean;
13
8
  id(): any;
14
9
  value(): any;
15
- uses(df: DataFlow, name?: string): void;
16
- find(name: string): DataFlow;
17
- findValue(name: string): any;
18
- usesReady(): boolean;
10
+ uses(df: DataFlow): void;
19
11
  usesStale(): boolean;
20
12
  usesRemember(): void;
13
+ ifcompute(): void;
14
+ compute(): void;
21
15
  }
22
- export declare class DataFlowNonNull extends DataFlow {
16
+ export declare class DataFlowCallback extends DataFlow {
23
17
  _value: any;
24
18
  _cb: () => any;
25
19
  constructor(cb: () => any);
26
- ready(): boolean;
27
20
  id(): any;
28
21
  value(): any;
29
22
  }
@@ -15,67 +15,57 @@
15
15
 
16
16
  interface UseItem
17
17
  {
18
- name: string,
19
18
  df: DataFlow,
20
19
  id?: any,
21
20
  }
22
21
 
23
22
  export class DataFlow
24
23
  {
25
- uniquename: number;
26
- usesList: { [name: string]: UseItem };
24
+ usesList: UseItem[];
27
25
 
28
26
  constructor()
29
27
  {
30
- this.usesList = {};
31
- this.uniquename = 1;
28
+ this.usesList = [];
32
29
  }
33
30
 
34
31
  // override in subclass
35
- ready(): boolean { return this.usesReady() }
36
32
  id(): any { return null }
37
33
  value(): any { return null }
38
34
 
39
- uses(df: DataFlow, name?: string): void
35
+ uses(df: DataFlow): void
40
36
  {
41
- if (!name) name = `_df_${this.uniquename++}`;
42
- this.usesList[name] = { name: name, df: df };
37
+ this.usesList.push({ df: df });
43
38
  }
44
39
 
45
- find(name: string): DataFlow
46
- {
47
- let ui = this.usesList[name];
48
- return ui ? ui.df : undefined;
49
- }
50
-
51
- findValue(name: string): any
40
+ usesStale(): boolean
52
41
  {
53
- let df = this.find(name);
54
- return df ? df.value() : undefined;
42
+ let isstale = false;
43
+ this.usesList.forEach(ui => { if (ui.id !== ui.df.id()) isstale = true });
44
+ return isstale;
55
45
  }
56
46
 
57
- usesReady(): boolean
47
+ usesRemember(): void
58
48
  {
59
- let isready = true;
60
- Object.values(this.usesList).forEach((ui: UseItem) => { if (!ui.df.ready()) isready = false });
61
- return isready;
49
+ this.usesList.forEach(ui => { ui.id = ui.df.id() });
62
50
  }
63
51
 
64
- usesStale(): boolean
52
+ ifcompute(): void
65
53
  {
66
- let isstale = false;
67
- Object.values(this.usesList).forEach((ui: UseItem) => { if (ui.df.id !== ui.df.id()) isstale = true });
68
- return isstale;
54
+ if (this.usesStale())
55
+ {
56
+ this.usesRemember();
57
+ this.compute();
58
+ }
69
59
  }
70
60
 
71
- usesRemember(): void
61
+ compute(): void
72
62
  {
73
- Object.values(this.usesList).forEach((ui: UseItem) => { ui.df.id = ui.df.id() });
74
63
  }
75
64
  }
76
65
 
77
- // Takes callback that, when ready, returns non-null. The return value is both the value and the id.
78
- export class DataFlowNonNull extends DataFlow
66
+ // Takes callback that, eventually, returns non-null. The return value is both the value and the id.
67
+ // Once the value returns non-null, the callback is never called again.
68
+ export class DataFlowCallback extends DataFlow
79
69
  {
80
70
  _value: any;
81
71
  _cb: () => any;
@@ -86,21 +76,6 @@ export class DataFlowNonNull extends DataFlow
86
76
  this._cb = cb;
87
77
  }
88
78
 
89
- ready(): boolean
90
- {
91
- // Allow chaining
92
- if (!this.usesReady())
93
- return false;
94
-
95
- // Real core semantics, with chaining on stale
96
- if (!this._value || this.usesStale())
97
- {
98
- this._value = this._cb();
99
- if (this._value) this.usesRemember();
100
- }
101
- return !!this._value;
102
- }
103
-
104
- id(): any { return this.ready(), this._value }
105
- value(): any { return this.ready(), this._value }
79
+ id(): any { if (!this._value) this._value = this._cb(); return this._value }
80
+ value(): any { return this.id() }
106
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.73",
3
+ "version": "1.0.75",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",