10BC0 Fix #1766 - Ensure correct hooks types by WebReflection · Pull Request #1772 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pyscript.core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyscript.core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions pyscript.core/src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 16 additions & 9 deletions pyscript.core/src/hooks.js
Original file line number Diff line number Diff line change
@@ -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(),
};
3 changes: 2 additions & 1 deletion pyscript.core/types/hooks.d.ts
Original file line number Diff line number Diff line change
@@ -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>;
Expand Down
0