Skip to content

Commit

Permalink
add js workers
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Jun 7, 2024
1 parent 6dfb026 commit 314384a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions includes/Templates/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use WCPOS\WooCommercePOS\Services\Auth;
use const WCPOS\WooCommercePOS\SHORT_NAME;
use const WCPOS\WooCommercePOS\VERSION;
use const WCPOS\WooCommercePOS\PLUGIN_URL;

/**
* Frontend class.
Expand Down Expand Up @@ -148,7 +149,15 @@ function ( $store ) {
$initial_props = wp_json_encode( $vars );
$dev_bundle = 'http://localhost:8081/index.bundle?platform=web&dev=true&hot=false';

// getScript helper and initialProps
/**
* Add path to worker scripts
*/
$idbWorker = PLUGIN_URL . 'assets/js/indexeddb.worker.js';
$mmIdbWorker = PLUGIN_URL . 'assets/js/memory-mapped-indexeddb.worker.js';

/**
* getScript helper and initialProps
*/
echo "<script>
function getScript(source, callback) {
var script = document.createElement('script');
Expand All @@ -168,9 +177,14 @@ function getScript(source, callback) {
prior.parentNode.insertBefore(script, prior);
}
var initialProps={$initial_props};
var idbWorker = '{$idbWorker}';
var mmIdbWorker = '{$mmIdbWorker}';
var initialProps = {$initial_props};
</script>" . "\n";

/**
* The actual app bundle
*/
if ( $development ) {
// Development
echo "<script>getScript('{$dev_bundle}' , () => { console.log('done') });</script>" . "\n";
Expand Down

0 comments on commit 314384a

Please sign in to comment.