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