wgge 2.0.42 → 2.1.0

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.
@@ -4,18 +4,32 @@ import ModelBase from "./ModelBase";
4
4
 
5
5
  export default class ObjectModel extends ModelBase {
6
6
 
7
+ propagateChangeEvent = false;
8
+
7
9
  /**
8
10
  * @type {Dictionary<ModelBase>}
9
11
  */
10
12
  properties;
11
13
 
12
- constructor(persistent = true) {
14
+ constructor(persistent = true, propagateChangeEvent = false) {
13
15
  super(persistent);
14
16
 
17
+ this.propagateChangeEvent = propagateChangeEvent;
18
+
15
19
  this.properties = new Dictionary();
16
20
  this.properties.addEventListener('add', (e) => this.propertyAdded(e.key, e.value));
17
21
  this.properties.addEventListener('remove', (e) => this.propertyRemoved(e.key, e.old));
18
22
  this.properties.addEventListener('set', (e) => this.propertySet(e.key, e.old, e.value));
23
+
24
+ this.propertyValueChangedHandler = () => this.triggerEvent('change');
25
+ }
26
+
27
+ subscribeToOnChangeEvent(property) {
28
+ property.addEventListener('change', this.propertyValueChangedHandler);
29
+ }
30
+
31
+ unsubscribeFromOnChangeEvent(property) {
32
+ property.removeEventListener('change', this.propertyValueChangedHandler);
19
33
  }
20
34
 
21
35
  addProperty(name, property) {
@@ -28,11 +42,13 @@ export default class ObjectModel extends ModelBase {
28
42
  propertyAdded(name, property) {
29
43
  this.makeDirty();
30
44
  this.subscribeToOnDirtyEvent(property);
45
+ if (this.propagateChangeEvent) this.subscribeToOnChangeEvent(property);
31
46
  }
32
47
 
33
48
  propertyRemoved(name, property) {
34
49
  this.makeDirty();
35
50
  this.unsubscribeFromOnDirtyEvent(property);
51
+ this.unsubscribeFromOnChangeEvent(property);
36
52
  }
37
53
 
38
54
  propertySet(name, oldProperty, newProperty) {
@@ -6,6 +6,8 @@ import {EVENT_REMOVE_ME} from "../ModelBase";
6
6
 
7
7
  export default class ModelNodeCollection extends ObjectModel {
8
8
 
9
+ propagateChangeEvent = false;
10
+
9
11
  /**
10
12
  * @type Collection
11
13
  */
@@ -18,9 +20,10 @@ export default class ModelNodeCollection extends ObjectModel {
18
20
  */
19
21
  selectedNode;
20
22
 
21
- constructor(nodeFactory = null, persistent = true) {
23
+ constructor(nodeFactory = null, persistent = true, propagateChangeEvent = false) {
22
24
  super(persistent);
23
25
 
26
+ this.propagateChangeEvent = propagateChangeEvent;
24
27
  this.nodeFactory = nodeFactory;
25
28
  this.children = new Collection();
26
29
  const events = ['add', 'insert', 'remove', 'change'];
@@ -34,7 +37,7 @@ export default class ModelNodeCollection extends ObjectModel {
34
37
  }
35
38
  this.remove(ch);
36
39
  }
37
-
40
+ this.childChangedHandler = () => this.triggerEvent('change');
38
41
  this.selectedNode = this.addProperty('selectedNode', new NullableNode(null, false));
39
42
  }
40
43
 
@@ -184,6 +187,7 @@ export default class ModelNodeCollection extends ObjectModel {
184
187
  this.makeDirty();
185
188
  this.subscribeToOnDirtyEvent(child);
186
189
  child.addEventListener(EVENT_REMOVE_ME, this.childRequestedRemoveHandler);
190
+ if (this.propagateChangeEvent) child.addEventListener('change', this.childChangedHandler);
187
191
  }
188
192
 
189
193
  /**
@@ -194,6 +198,7 @@ export default class ModelNodeCollection extends ObjectModel {
194
198
  this.makeDirty();
195
199
  this.unsubscribeFromOnDirtyEvent(child);
196
200
  child.removeEventListener(EVENT_REMOVE_ME, this.childRequestedRemoveHandler);
201
+ child.removeEventListener('change', this.childChangedHandler);
197
202
  if (this.selectedNode.equalsTo(child)) {
198
203
  this.selectedNode.set(null);
199
204
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wgge",
3
- "version": "2.0.42",
3
+ "version": "2.1.0",
4
4
  "description": "Web GL Game Engine",
5
5
  "main": "index.js",
6
6
  "devDependencies": {