@duet3d/objectmodel 3.6.0-beta.6 → 3.6.0-beta.7

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.
@@ -3,9 +3,6 @@ import { IModelObject } from "./ModelObject";
3
3
  * Class for storing model object items in an array
4
4
  */
5
5
  export declare class ModelCollection<T extends IModelObject | null> extends Array<T> implements IModelObject {
6
- readonly itemConstructor: {
7
- new (): T;
8
- };
9
6
  /**
10
7
  * Constructor of this class
11
8
  * @param itemConstructor Item constructor type that items must derive from
@@ -14,8 +14,8 @@ class ModelCollection extends Array {
14
14
  */
15
15
  constructor(itemConstructor) {
16
16
  super();
17
- this.itemConstructor = itemConstructor;
18
17
  Object.setPrototypeOf(this, ModelCollection.prototype);
18
+ Object.defineProperty(this, "$itemConstructor", { enumerable: false, value: itemConstructor });
19
19
  }
20
20
  // Unfortunately it isn't possible to override index operators in JS/TS
21
21
  /**
@@ -23,12 +23,13 @@ class ModelCollection extends Array {
23
23
  * @param items Items to add
24
24
  */
25
25
  push(...items) {
26
+ const that = this;
26
27
  for (const item of items) {
27
- if (item === null || item instanceof this.itemConstructor) {
28
+ if (item === null || item instanceof that.$itemConstructor) {
28
29
  super.push(item);
29
30
  }
30
31
  else {
31
- const newItem = new this.itemConstructor();
32
+ const newItem = new that.$itemConstructor();
32
33
  super.push(newItem.update(item));
33
34
  }
34
35
  }
@@ -46,6 +47,7 @@ class ModelCollection extends Array {
46
47
  if (!(jsonElement instanceof Array)) {
47
48
  throw new Error(`Invalid JSON element type for model collection ${typeof jsonElement}`);
48
49
  }
50
+ const that = this;
49
51
  // Remove deleted items
50
52
  this.splice(jsonElement.length);
51
53
  // Update existing items
@@ -53,11 +55,11 @@ class ModelCollection extends Array {
53
55
  const currentItem = this[i];
54
56
  if (currentItem === null) {
55
57
  const newItem = jsonElement[i];
56
- if (newItem instanceof this.itemConstructor) {
58
+ if (newItem instanceof that.$itemConstructor) {
57
59
  (0, index_1.setArrayItem)(this, i, jsonElement[i]);
58
60
  }
59
61
  else {
60
- const refItem = new this.itemConstructor();
62
+ const refItem = new that.$itemConstructor();
61
63
  (0, index_1.setArrayItem)(this, i, refItem.update(newItem));
62
64
  }
63
65
  }
@@ -81,7 +83,7 @@ class ModelCollection extends Array {
81
83
  super.push(itemToAdd);
82
84
  }
83
85
  else {
84
- const newItem = new this.itemConstructor();
86
+ const newItem = new that.$itemConstructor();
85
87
  super.push(newItem.update(itemToAdd));
86
88
  }
87
89
  }
@@ -3,10 +3,6 @@ import { IModelObject } from "./ModelObject";
3
3
  * Dictionary class to map object model data
4
4
  */
5
5
  export declare class ModelDictionary<T> extends Map<string, T | null> implements IModelObject {
6
- readonly nullDeletesKeys: boolean;
7
- readonly itemConstructor: {
8
- new (): T;
9
- } | null;
10
6
  /**
11
7
  * Constructor of this class
12
8
  * @param nullDeletesKeys Whether setting null to items effectively deletes them
@@ -14,9 +14,9 @@ class ModelDictionary extends Map {
14
14
  */
15
15
  constructor(nullDeletesKeys, itemConstructor = null) {
16
16
  super();
17
- this.nullDeletesKeys = nullDeletesKeys;
18
- this.itemConstructor = itemConstructor;
19
17
  Object.setPrototypeOf(this, ModelDictionary.prototype);
18
+ Object.defineProperty(this, "$nullDeletesKeys", { enumerable: false, value: nullDeletesKeys });
19
+ Object.defineProperty(this, "$itemConstructor", { enumerable: false, value: itemConstructor });
20
20
  }
21
21
  /**
22
22
  * Overridden set method to perform type-checks and update
@@ -24,8 +24,9 @@ class ModelDictionary extends Map {
24
24
  * @param value Value to set
25
25
  */
26
26
  set(key, value) {
27
+ const that = this;
27
28
  if (value === null) {
28
- if (this.nullDeletesKeys) {
29
+ if (that.$nullDeletesKeys) {
29
30
  this.delete(key);
30
31
  return this;
31
32
  }
@@ -33,8 +34,8 @@ class ModelDictionary extends Map {
33
34
  }
34
35
  const currentItem = this.get(key);
35
36
  if (currentItem == null) {
36
- if (this.itemConstructor !== null && !(value instanceof this.itemConstructor)) {
37
- const newItem = new this.itemConstructor();
37
+ if (that.$itemConstructor !== null && !(value instanceof that.$itemConstructor)) {
38
+ const newItem = new that.$itemConstructor();
38
39
  if ((0, ModelObject_1.isModelObject)(newItem)) {
39
40
  const updatedItem = newItem.update(value);
40
41
  return super.set(key, updatedItem);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duet3d/objectmodel",
3
- "version": "3.6.0-beta.6",
3
+ "version": "3.6.0-beta.7",
4
4
  "description": "TypeScript implementation of the Duet3D Object Model",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",