kungfooman / RuntimeTypeInspector.js

Checking JSDoc types at runtime for high-quality types - Trust is good, control is better.
MIT License
8 stars 0 forks source link

Rely on sending and receiving messages instead of direct DOM access #194

Closed kungfooman closed 1 month ago

kungfooman commented 1 month ago

The main goal is to enable type checking inside workers. I spent some time working on https://github.com/kungfooman/worker-with-import-map

This enables import maps inside workers, allowing us to dynamically enable RTI.js for a project even within a worker:

if (location.search.includes("rti")) {
  imports['@xenova/transformers'] = "/transformer/transformers.js-rti/dist/transformers.rti.js";
}

If no rti is in the URL, types won't be checked. Now the main issue is that the entire lib may be executed in a Worker. Since there is no access to any DOM through a Worker, we have to send and receive messages.

This is something that also will help custom UI's like in PlayCanvas Examples browser where the RTI type checked engine is running in an <iframe> while the React UI is controlling the display of the catched errors - and not the little RTI UI, that just may not fit well into existing designs.