@digo-org/digo-api 1.0.21 → 1.0.22
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.
- package/package.json +1 -1
- package/src/digo-asset.ts +30 -14
- package/src/index.ts +1 -1
package/package.json
CHANGED
package/src/digo-asset.ts
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
import { ReactNode }
|
2
|
-
import { SingleParameterValue } from 'src/types';
|
1
|
+
import { ReactNode } from 'react';
|
2
|
+
import { Instance, SingleParameterValue } from 'src/types';
|
3
3
|
|
4
4
|
export abstract class DigoAsset {
|
5
5
|
protected rootElement: any = null;
|
6
6
|
|
7
|
+
protected instances: Instance[] = [];
|
8
|
+
|
7
9
|
constructor() {
|
8
10
|
this.handleMessage = this.handleMessage.bind(this);
|
9
11
|
|
@@ -29,25 +31,39 @@ export abstract class DigoAsset {
|
|
29
31
|
private handleMessage(event: MessageEvent): void {
|
30
32
|
const message = event.data;
|
31
33
|
|
32
|
-
if (message
|
33
|
-
const parameterId = message.parameterId;
|
34
|
-
const value = message.value;
|
35
|
-
const isGlobal = message.isGlobal;
|
36
|
-
const entityId = message.entityId;
|
34
|
+
if (!message) return;
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
switch (message.command) {
|
37
|
+
case 'SET_PARAMETER':{
|
38
|
+
const parameterId = message.parameterId;
|
39
|
+
const value = message.value;
|
40
|
+
const isGlobal = message.isGlobal;
|
41
|
+
const entityId = message.entityId;
|
42
|
+
|
43
|
+
if (isGlobal) {
|
44
|
+
this.onGlobalParameterChange(parameterId, value);
|
45
|
+
} else {
|
46
|
+
this.onEntityParameterChange(parameterId, entityId, value);
|
47
|
+
}
|
48
|
+
|
49
|
+
if (this.onParameterChange) this.onParameterChange(parameterId, entityId, value, isGlobal);
|
50
|
+
|
51
|
+
break;
|
45
52
|
}
|
53
|
+
|
54
|
+
case 'UPDATE_INSTANCES':
|
55
|
+
this.instances = message.instances;
|
56
|
+
|
57
|
+
if (this.onInstancesUpdated) this.onInstancesUpdated();
|
58
|
+
|
59
|
+
break;
|
46
60
|
}
|
61
|
+
|
47
62
|
this.updateUI();
|
48
63
|
}
|
49
64
|
|
50
65
|
onParameterChange?(parameterId: string, entityId: string, value: SingleParameterValue, isGlobal: boolean): void;
|
66
|
+
onInstancesUpdated?(): void;
|
51
67
|
|
52
68
|
abstract onGlobalParameterChange(parameterId: string, value: SingleParameterValue): void;
|
53
69
|
abstract onEntityParameterChange(parameterId: string, entityId: string, value: SingleParameterValue): void;
|
package/src/index.ts
CHANGED