@@ -12,5 +12,42 @@ core itself.
12
12
Here's an example of how a PyScript plugin looks like:
13
13
14
14
``` js
15
+ // import the hooks from PyScript first...
16
+ import { hooks } from " <path_to_pyscript>/core.js" ;
15
17
18
+ // Use the `main` attribute on hooks do define plugins that run on the main thread
19
+ hooks .main .onReady .add ((wrap , element ) => {
20
+ console .log (" main" , " onReady" );
21
+ if (location .search === ' ?debug' ) {
22
+ console .debug (" main" , " wrap" , wrap);
23
+ console .debug (" main" , " element" , element);
24
+ }
25
+ });
26
+ hooks .main .onBeforeRun .add (() => {
27
+ console .log (" main" , " onBeforeRun" );
28
+ });
29
+ hooks .main .codeBeforeRun .add (' print("main", "codeBeforeRun")' );
30
+ hooks .main .codeAfterRun .add (' print("main", "codeAfterRun")' );
31
+ hooks .main .onAfterRun .add (() => {
32
+ console .log (" main" , " onAfterRun" );
33
+ });
34
+
35
+ // Use the `worker` attribute on hooks do define plugins that run on workers
36
+ hooks .worker .onReady .add ((wrap , xworker ) => {
37
+ console .log (" worker" , " onReady" );
38
+ if (location .search === ' ?debug' ) {
39
+ console .debug (" worker" , " wrap" , wrap);
40
+ console .debug (" worker" , " xworker" , xworker);
41
+ }
42
+ });
43
+
44
+ hooks .worker .onBeforeRun .add (() => {
45
+ console .log (" worker" , " onBeforeRun" );
46
+ });
47
+
48
+ hooks .worker .codeBeforeRun .add (' print("worker", "codeBeforeRun")' );
49
+ hooks .worker .codeAfterRun .add (' print("worker", "codeAfterRun")' );
50
+ hooks .worker .onAfterRun .add (() => {
51
+ console .log (" worker" , " onAfterRun" );
52
+ });
16
53
```
0 commit comments