anvilistas / anvil-labs

MIT License
9 stars 3 forks source link

web worker: Updates #89

Closed s-cork closed 1 year ago

s-cork commented 1 year ago

Features:

Import arbitrary app modules from inside the web_worker module

this includes dependencies - i.e. from anvil_extras import storage should just work To make it work we need anvil.js as a module available in the webworker (anvil_extras.storage uses it). So I create a dummy module since we don't have access to the real anvil.js module I also add anvil.server as a dummy module since it allows us to call anvil.server.get_api_endpoint() from within the webworker. (We could extend the anvil.server module to include anvil.server.call - but this might be too cute - it would only mimic the real anvil.sever.call behaviour and would likely fail in unexpected ways)_

Breaking change:

Anyone using web workers will need to add:

<script src="_/theme/anvil-labs/worker.js" defer></script>

to their native libraries This script allows us to intercept python source code from the app and save it for later, to be injected into the web worker. This seemed like the best approach since it's not exposed by anvil. (see js/pre-worker/mod.ts)

We could do this later, but later might be too late, so putting it in Native Libraries seemed best.

This approach should help us with background-sync later.


@rhurlbatt - are you using anvil-labs as a dependency? If you are you should add the above script tags before we merge this ❗️⚠️

rhurlbatt commented 1 year ago

@s-cork We are using this as a dependency but I will revert to using the code in a standalone module until we have verified everything. Give me 10 Minutes.

rhurlbatt commented 1 year ago

@s-cork we are now working off a module and have added the above script in. All good to go from our end - Thank you.