@drayman/core 1.4.0 → 1.5.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.
- package/dist/component-processor.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +52 -47
- package/package.json +3 -3
|
@@ -216,6 +216,9 @@ const initializeComponentInstance = async ({ componentInstanceId, browserCommand
|
|
|
216
216
|
// const delta = jsondiff.diff(previouslySerializedTree, result.tree);
|
|
217
217
|
// const delta = compare(previouslySerializedTree, result.tree);
|
|
218
218
|
sendMessage({ type: 'view', payload: { view: result.tree, updateId } });
|
|
219
|
+
if (updateId === 1 && ComponentInstance.onInit) {
|
|
220
|
+
await ComponentInstance.onInit();
|
|
221
|
+
}
|
|
219
222
|
// previouslySerializedTree = { ...result.tree };
|
|
220
223
|
// previouslySerializedTree = JSON.parse(JSON.stringify(result.tree));
|
|
221
224
|
// process?.send?.({ type: 'view', payload: { view: serializedView } });
|
package/dist/index.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare const onInitializeComponentInstance: ({ namespaceId, extensionsPa
|
|
|
43
43
|
}) => Promise<void>;
|
|
44
44
|
export declare const onDisconnect: ({ connectionId }: {
|
|
45
45
|
connectionId: any;
|
|
46
|
-
}) => void
|
|
46
|
+
}) => Promise<void>;
|
|
47
47
|
export declare const onDestroyComponentInstance: ({ componentInstanceId }: {
|
|
48
48
|
componentInstanceId: any;
|
|
49
49
|
}) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -93,61 +93,66 @@ const onInitializeComponentInstance = async ({ namespaceId = null, extensionsPat
|
|
|
93
93
|
connectionId,
|
|
94
94
|
namespaceId,
|
|
95
95
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*/
|
|
105
|
-
if (type === 'response') {
|
|
106
|
-
const { requestId, result, err } = payload;
|
|
107
|
-
if (err) {
|
|
108
|
-
exports.componentInstances[componentInstanceId].eventRequests[requestId].onError({ err });
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
exports.componentInstances[componentInstanceId].eventRequests[requestId].onSuccess({ result });
|
|
112
|
-
}
|
|
113
|
-
delete exports.componentInstances[componentInstanceId].eventRequests[requestId];
|
|
114
|
-
}
|
|
115
|
-
else if (type === 'eventHubEvent') {
|
|
116
|
-
const { eventPayload, groupId, type } = payload;
|
|
117
|
-
exports.handleEventHubEvent({ data: eventPayload, groupId, type, namespaceId });
|
|
118
|
-
}
|
|
119
|
-
else if (type === 'console') {
|
|
120
|
-
const { text } = payload;
|
|
121
|
-
onComponentInstanceConsole?.({ text });
|
|
96
|
+
worker.events().subscribe(({ type, payload }) => {
|
|
97
|
+
/**
|
|
98
|
+
* When there is a response to user event request.
|
|
99
|
+
*/
|
|
100
|
+
if (type === 'response') {
|
|
101
|
+
const { requestId, result, err } = payload;
|
|
102
|
+
if (err) {
|
|
103
|
+
exports.componentInstances[componentInstanceId].eventRequests[requestId].onError({ err });
|
|
122
104
|
}
|
|
123
105
|
else {
|
|
124
|
-
|
|
106
|
+
exports.componentInstances[componentInstanceId].eventRequests[requestId].onSuccess({ result });
|
|
125
107
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
108
|
+
delete exports.componentInstances[componentInstanceId].eventRequests[requestId];
|
|
109
|
+
}
|
|
110
|
+
else if (type === 'eventHubEvent') {
|
|
111
|
+
const { eventPayload, groupId, type } = payload;
|
|
112
|
+
exports.handleEventHubEvent({ data: eventPayload, groupId, type, namespaceId });
|
|
113
|
+
}
|
|
114
|
+
else if (type === 'console') {
|
|
115
|
+
const { text } = payload;
|
|
116
|
+
onComponentInstanceConsole?.({ text });
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
emit({ type, payload, componentInstanceId });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
worker.initializeComponentInstance({ browserCommands, componentNamePrefix, componentName, componentRootDir, componentOptions, componentInstanceId, extensionsPath, extensionsOptions });
|
|
123
|
+
await clearGarbage();
|
|
129
124
|
};
|
|
130
125
|
exports.onInitializeComponentInstance = onInitializeComponentInstance;
|
|
131
|
-
const onDisconnect = ({ connectionId }) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
126
|
+
const onDisconnect = async ({ connectionId }) => {
|
|
127
|
+
garbage.connections.push(connectionId);
|
|
128
|
+
await clearGarbage();
|
|
135
129
|
};
|
|
136
130
|
exports.onDisconnect = onDisconnect;
|
|
137
|
-
const
|
|
131
|
+
const garbage = {
|
|
132
|
+
connections: [],
|
|
133
|
+
componentInstances: [],
|
|
134
|
+
};
|
|
138
135
|
const onDestroyComponentInstance = async ({ componentInstanceId }) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
try {
|
|
144
|
-
await exports.componentInstances[componentInstanceId].worker.handleDestroyComponentInstance();
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
console.warn(err);
|
|
148
|
-
}
|
|
149
|
-
exports.componentInstances[componentInstanceId].terminate();
|
|
150
|
-
}
|
|
136
|
+
garbage.componentInstances.push(componentInstanceId);
|
|
137
|
+
await clearGarbage();
|
|
151
138
|
};
|
|
152
139
|
exports.onDestroyComponentInstance = onDestroyComponentInstance;
|
|
153
140
|
exports.componentInstances = {};
|
|
141
|
+
const clearGarbage = async () => {
|
|
142
|
+
const aliveComponentInstances = Object.keys(exports.componentInstances);
|
|
143
|
+
const garbageComponentInstanceIds = [
|
|
144
|
+
...aliveComponentInstances.filter(x => garbage.connections.includes(exports.componentInstances[x].connectionId)),
|
|
145
|
+
...garbage.componentInstances,
|
|
146
|
+
];
|
|
147
|
+
for (const componentInstanceId of garbageComponentInstanceIds) {
|
|
148
|
+
if (exports.componentInstances[componentInstanceId]) {
|
|
149
|
+
try {
|
|
150
|
+
await exports.componentInstances[componentInstanceId].worker.handleDestroyComponentInstance();
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
console.warn(err);
|
|
154
|
+
}
|
|
155
|
+
exports.componentInstances[componentInstanceId].terminate();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drayman/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@babel/preset-env": "^7.13.15",
|
|
23
23
|
"@babel/preset-react": "^7.13.13",
|
|
24
24
|
"@babel/preset-typescript": "^7.13.0",
|
|
25
|
-
"@drayman/types": "^1.
|
|
25
|
+
"@drayman/types": "^1.5.0",
|
|
26
26
|
"@types/jest": "^26.0.22",
|
|
27
27
|
"@types/node": "^14.14.39",
|
|
28
28
|
"babel-jest": "^26.6.3",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"ts-node": "^9.1.1",
|
|
40
40
|
"typescript": "~4.1.5"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "072618ea36a1d151c16e5233c502ad737eec5785"
|
|
43
43
|
}
|