Fix #1766 - Ensure correct hooks types (#1772)

This commit is contained in:
Andrea Giammarchi
2023-09-29 14:01:35 +02:00
committed by GitHub
parent 7a23e355b9
commit 5c4e400d32
5 changed files with 29 additions and 12 deletions

View File

@@ -11,7 +11,8 @@
"dependencies": {
"@ungap/with-resolvers": "^0.1.0",
"basic-devtools": "^0.1.6",
"polyscript": "^0.4.8"
"polyscript": "^0.4.8",
"type-checked-collections": "^0.1.7"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.1",
@@ -2802,6 +2803,11 @@
"node": ">= 0.8.0"
}
},
"node_modules/type-checked-collections": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/type-checked-collections/-/type-checked-collections-0.1.7.tgz",
"integrity": "sha512-fLIydlJy7IG9XL4wjRwEcKhxx/ekLXiWiMvcGo01cOMF+TN+5ZqajM1mRNRz2bNNi1bzou2yofhjZEQi7kgl9A=="
},
"node_modules/type-fest": {
"version": "0.20.2",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz",

View File

@@ -33,7 +33,8 @@
"dependencies": {
"@ungap/with-resolvers": "^0.1.0",
"basic-devtools": "^0.1.6",
"polyscript": "^0.4.8"
"polyscript": "^0.4.8",
"type-checked-collections": "^0.1.7"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.1",

View File

@@ -137,6 +137,8 @@ for (const [TYPE, interpreter] of TYPES) {
...workerHooks,
onWorkerReady(_, xworker) {
assign(xworker.sync, sync);
for (const callback of hooks.onWorkerReady)
callback(_, xworker);
},
onBeforeRun(wrap, element) {
currentElement = element;

View File

@@ -1,21 +1,28 @@
import { typedSet } from "type-checked-collections";
const SetFunction = typedSet({ typeof: "function" });
const SetString = typedSet({ typeof: "string" });
export default {
/** @type {Set<function>} */
onBeforeRun: new Set(),
onInterpreterReady: new SetFunction(),
/** @type {Set<function>} */
onBeforeRunAsync: new Set(),
onBeforeRun: new SetFunction(),
/** @type {Set<function>} */
onAfterRun: new Set(),
onBeforeRunAsync: new SetFunction(),
/** @type {Set<function>} */
onAfterRunAsync: new Set(),
onAfterRun: new SetFunction(),
/** @type {Set<function>} */
onInterpreterReady: new Set(),
onAfterRunAsync: new SetFunction(),
/** @type {Set<function>} */
onWorkerReady: new SetFunction(),
/** @type {Set<string>} */
codeBeforeRunWorker: new Set(),
codeBeforeRunWorker: new SetString(),
/** @type {Set<string>} */
codeBeforeRunWorkerAsync: new Set(),
codeBeforeRunWorkerAsync: new SetString(),
/** @type {Set<string>} */
codeAfterRunWorker: new Set(),
codeAfterRunWorker: new SetString(),
/** @type {Set<string>} */
codeAfterRunWorkerAsync: new Set(),
codeAfterRunWorkerAsync: new SetString(),
};

View File

@@ -1,9 +1,10 @@
declare namespace _default {
let onInterpreterReady: Set<Function>;
let onBeforeRun: Set<Function>;
let onBeforeRunAsync: Set<Function>;
let onAfterRun: Set<Function>;
let onAfterRunAsync: Set<Function>;
let onInterpreterReady: Set<Function>;
let onWorkerReady: Set<Function>;
let codeBeforeRunWorker: Set<string>;
let codeBeforeRunWorkerAsync: Set<string>;
let codeAfterRunWorker: Set<string>;