8000 Fix #1766 - Ensure correct hooks types (#1772) · LakshmanKishore/pyscript@5c4e400 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 5c4e400

Browse files
Fix pyscript#1766 - Ensure correct hooks types (pyscript#1772)
1 parent 7a23e35 commit 5c4e400

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

pyscript.core/package-lock.json

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyscript.core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"dependencies": {
3434
"@ungap/with-resolvers": "^0.1.0",
3535
"basic-devtools": "^0.1.6",
36-
"polyscript": "^0.4.8"
36+
"polyscript": "^0.4.8",
37+
"type-checked-collections": "^0.1.7"
3738
},
3839
"devDependencies": {
3940
"@rollup/plugin-node-resolve": "^15.2.1",

pyscript.core/src/core.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ for (const [TYPE, interpreter] of TYPES) {
137137
...workerHooks,
138138
onWorkerReady(_, xworker) {
139139
assign(xworker.sync, sync);
140+
for (const callback of hooks.onWorkerReady)
141+
callback(_, xworker);
140142
},
141143
onBeforeRun(wrap, element) {
142144
currentElement = element;

pyscript.core/src/hooks.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1+
import { typedSet } from "type-checked-collections";
2+
3+
const SetFunction = typedSet({ typeof: "function" });
4+
const SetString = typedSet({ typeof: "string" });
5+
16
export default {
27
/** @type {Set<function>} */
3-
onBeforeRun: new Set(),
8+
onInterpreterReady: new SetFunction(),
49
/** @type {Set<function>} */
5-
onBeforeRunAsync: new Set(),
10+
onBeforeRun: new SetFunction(),
611
/** @type {Set<function>} */
7-
onAfterRun: new Set(),
12+
onBeforeRunAsync: new SetFunction(),
813
/** @type {Set<function>} */
9-
onAfterRunAsync: new Set(),
14+
onAfterRun: new SetFunction(),
1015
/** @type {Set<function>} */
11-
onInterpreterReady: new Set(),
16+
onAfterRunAsync: new SetFunction(),
1217

18+
/** @type {Set<function>} */
19+
onWorkerReady: new SetFunction(),
1320
/** @type {Set<string>} */
14-
codeBeforeRunWorker: new Set(),
21+
codeBeforeRunWorker: new SetString(),
1522
/** @type {Set<string>} */
16-
codeBeforeRunWorkerAsync: new Set(),
23+
codeBeforeRunWorkerAsync: new SetString(),
1724
/** @type {Set<string>} */
18-
codeAfterRunWorker: new Set(),
25+
codeAfterRunWorker: new SetString(),
1926
/** @type {Set<string>} */
20-
codeAfterRunWorkerAsync: new Set(),
27+
codeAfterRunWorkerAsync: new SetString(),
2128
};

pyscript.core/types/hooks.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
declare namespace _default {
2+
let onInterpreterReady: Set<Function>;
23
let onBeforeRun: Set<Function>;
34
let onBeforeRunAsync: Set<Function>;
45
let onAfterRun: Set<Function>;
56
let onAfterRunAsync: Set<Function>;
6-
let onInterpreterReady: Set<Function>;
7+
let onWorkerReady: Set<Function>;
78
let codeBeforeRunWorker: Set<string>;
89
let codeBeforeRunWorkerAsync: Set<string>;
910
let codeAfterRunWorker: Set<string>;

0 commit comments

Comments
 (0)
0