@dra2020/baseclient 1.0.102 → 1.0.104

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.
@@ -9,6 +9,7 @@ interface UseItem {
9
9
  }
10
10
  export declare class DataFlow {
11
11
  usesList: UseItem[];
12
+ inCompute: boolean;
12
13
  constructor();
13
14
  dfid(): any;
14
15
  compute(): void;
@@ -1,4 +1,5 @@
1
1
  import * as FSM from '../fsm/all';
2
+ import * as G from '../geo/all';
2
3
  import * as P from './poly';
3
4
  import * as Q from './quad';
4
5
  export declare type Topo = any;
@@ -15,30 +16,32 @@ export declare function topoMerge(topo: Topo, geoids: string[]): any;
15
16
  export declare function topoMergeFeatures(topo: Topo, features: any[]): any;
16
17
  declare class FsmIncrementalUnion extends FSM.Fsm {
17
18
  options: P.TickOptions;
18
- key: any;
19
+ key: number;
20
+ multi: G.GeoMultiCollection;
19
21
  map: any;
20
22
  result: any;
21
23
  work: Q.WorkDone;
22
- constructor(env: FSM.FsmEnvironment, options: P.TickOptions, key: any, map?: any);
23
- matches(key: any): boolean;
24
+ constructor(env: FSM.FsmEnvironment, options: P.TickOptions, multi: G.GeoMultiCollection, key: number, map?: any);
24
25
  recompute(map: any): void;
25
26
  cancel(): void;
26
27
  tick(): void;
27
28
  }
28
29
  export interface TopoUnionResult {
29
- key: any;
30
+ key: number;
30
31
  poly: any;
31
32
  work: Q.WorkDone;
32
33
  }
33
34
  export declare class FsmTopoUnion extends FSM.Fsm {
34
35
  options: P.TickOptions;
35
- unions: FsmIncrementalUnion[];
36
+ unions: {
37
+ [index: number]: FsmIncrementalUnion;
38
+ };
36
39
  work: Q.WorkDone;
37
40
  constructor(env: FSM.FsmEnvironment, options?: P.TickOptions);
38
41
  get result(): TopoUnionResult[];
39
42
  cancel(): void;
40
- cancelOne(key: any): void;
41
- recompute(key: any, map: any): void;
43
+ cancelOne(key: number): void;
44
+ recompute(multi: G.GeoMultiCollection, key: number, map: any): void;
42
45
  tick(): void;
43
46
  }
44
47
  export declare function topoPacked(topo: any): boolean;
@@ -26,10 +26,12 @@ interface UseItem
26
26
  export class DataFlow
27
27
  {
28
28
  usesList: UseItem[];
29
+ inCompute: boolean;
29
30
 
30
31
  constructor()
31
32
  {
32
33
  this.usesList = [];
34
+ this.inCompute = false;
33
35
  }
34
36
 
35
37
  // override in subclass
@@ -70,8 +72,12 @@ export class DataFlow
70
72
  {
71
73
  if (this.stale())
72
74
  {
75
+ if (this.inCompute)
76
+ console.log(`DataFlow compute reentrancy: ${this.constructor?.name}`);
77
+ this.inCompute = true;
73
78
  this.remember();
74
79
  this.compute();
80
+ this.inCompute = false;
75
81
  }
76
82
  }
77
83
  }
package/lib/poly/topo.ts CHANGED
@@ -8,6 +8,7 @@ import * as TopoSimplify from '@dra2020/topojson-simplify';
8
8
 
9
9
  import * as Util from '../util/all';
10
10
  import * as FSM from '../fsm/all';
11
+ import * as G from '../geo/all';
11
12
 
12
13
  import * as P from './poly';
13
14
  import * as Q from './quad';
@@ -362,26 +363,23 @@ let FSM_COMPUTING = UniqueState++;
362
363
  class FsmIncrementalUnion extends FSM.Fsm
363
364
  {
364
365
  options: P.TickOptions;
365
- key: any;
366
+ key: number;
367
+ multi: G.GeoMultiCollection;
366
368
  map: any; // { [geoid: string]: Feature }
367
369
  result: any;
368
370
  work: Q.WorkDone;
369
371
 
370
- constructor(env: FSM.FsmEnvironment, options: P.TickOptions, key: any, map?: any)
372
+ constructor(env: FSM.FsmEnvironment, options: P.TickOptions, multi: G.GeoMultiCollection, key: number, map?: any)
371
373
  {
372
374
  super(env);
373
375
  this.options = options;
376
+ this.multi = multi;
374
377
  this.key = key;
375
378
  this.result = null;
376
379
  this.map = null;
377
380
  if (map) this.recompute(map);
378
381
  }
379
382
 
380
- matches(key: any): boolean
381
- {
382
- return Util.shallowEqual(this.key, key);
383
- }
384
-
385
383
  recompute(map: any): void
386
384
  {
387
385
  if (this.map != null && map != null && Util.shallowEqual(map, this.map))
@@ -399,7 +397,7 @@ class FsmIncrementalUnion extends FSM.Fsm
399
397
  let values = Object.values(map);
400
398
  this.work = { nUnion: values.length, nDifference: 0, ms: 0 };
401
399
  let elapsed = new Util.Elapsed();
402
- this.result = topoMergeFeatures(this.key.multi.allTopo(), values);
400
+ this.result = topoMergeFeatures(this.multi.allTopo(), values);
403
401
  this.work.ms = elapsed.ms();
404
402
  this.map = map;
405
403
  }
@@ -430,7 +428,7 @@ class FsmIncrementalUnion extends FSM.Fsm
430
428
 
431
429
  export interface TopoUnionResult
432
430
  {
433
- key: any;
431
+ key: number;
434
432
  poly: any;
435
433
  work: Q.WorkDone;
436
434
  }
@@ -438,59 +436,51 @@ export interface TopoUnionResult
438
436
  export class FsmTopoUnion extends FSM.Fsm
439
437
  {
440
438
  options: P.TickOptions;
441
- unions: FsmIncrementalUnion[];
439
+ unions: { [index: number]: FsmIncrementalUnion };
442
440
  work: Q.WorkDone;
443
441
 
444
442
  constructor(env: FSM.FsmEnvironment, options?: P.TickOptions)
445
443
  {
446
444
  super(env);
447
445
  this.options = Util.shallowAssignImmutable(P.DefaultTickOptions, options);
448
- this.unions = [];
446
+ this.unions = {};
449
447
  this.work = { nUnion: 0, nDifference: 0, ms: 0 };
450
448
  }
451
449
 
452
450
  get result(): TopoUnionResult[]
453
451
  {
454
- if (this.unions.length > 0 && this.state === FSM.FSM_DONE)
455
- return this.unions.map((i: FsmIncrementalUnion) => ({ key: i.key, poly: i.result, work: i.work }) );
452
+ if (Util.countKeys(this.unions) > 0 && this.state === FSM.FSM_DONE)
453
+ return Object.values(this.unions).map((i: FsmIncrementalUnion) => ({ key: i.key, poly: i.result, work: i.work }) );
456
454
  else
457
455
  return null;
458
456
  }
459
457
 
460
458
  cancel(): void
461
459
  {
462
- this.unions.forEach((i: FsmIncrementalUnion) => {
460
+ Object.values(this.unions).forEach((i: FsmIncrementalUnion) => {
463
461
  i.cancel();
464
462
  });
465
- this.unions = [];
463
+ this.unions = {};
466
464
  this.setState(FSM.FSM_DONE);
467
465
  }
468
466
 
469
- cancelOne(key: any): void
467
+ cancelOne(key: number): void
470
468
  {
471
- for (let i = 0; i < this.unions.length; i++)
472
- {
473
- let u = this.unions[i];
474
- if (u.matches(key))
475
- {
476
- u.cancel();
477
- return;
478
- }
479
- }
469
+ let u = this.unions[key];
470
+ if (u) u.cancel();
480
471
  }
481
472
 
482
- recompute(key: any, map: any): void
473
+ recompute(multi: G.GeoMultiCollection, key: number, map: any): void
483
474
  {
484
- let fsm: FsmIncrementalUnion = this.unions.find((i: FsmIncrementalUnion) => i.matches(key));
485
- if (fsm == null)
475
+ let fsm = this.unions[key];
476
+ if (fsm == null || fsm.multi !== multi)
486
477
  {
487
- fsm = new FsmIncrementalUnion(this.env, this.options, key, map);
488
- this.unions.push(fsm);
478
+ fsm = new FsmIncrementalUnion(this.env, this.options, multi, key, map);
479
+ this.unions[key] = fsm;
489
480
  }
490
481
  else
491
482
  fsm.recompute(map);
492
483
  this.work = { nUnion: 0, nDifference: 0, ms: 0 };
493
- this.unions.forEach((u) => { this.work.nUnion += u.work.nUnion; this.work.nDifference += u.work.nDifference });
494
484
  this.waitOn(fsm);
495
485
  this.setState(FSM_COMPUTING);
496
486
  }
@@ -503,7 +493,12 @@ export class FsmTopoUnion extends FSM.Fsm
503
493
  {
504
494
  case FSM.FSM_STARTING:
505
495
  case FSM_COMPUTING:
506
- if (this.unions) this.unions.forEach((u) => { this.work.ms += u.work.ms });
496
+ this.work = { nUnion: 0, nDifference: 0, ms: 0 };
497
+ if (this.unions) Object.values(this.unions).forEach((i: FsmIncrementalUnion) => {
498
+ this.work.ms += i.work.ms;
499
+ this.work.nUnion += i.work.nUnion;
500
+ this.work.nDifference += i.work.nDifference;
501
+ });
507
502
  this.setState(FSM.FSM_DONE);
508
503
  break;
509
504
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.102",
3
+ "version": "1.0.104",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",