-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load WASM/JS files dynamically using importScripts (#40)
- Loading branch information
1 parent
62c60c7
commit 95e66f7
Showing
12 changed files
with
89 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import * as GrepModule from '../wasm/grep'; | ||
import { WasmCommandRunner } from './wasm_command_runner'; | ||
import { WasmLoader } from '../wasm_loader'; | ||
|
||
export class GrepCommandRunner extends WasmCommandRunner { | ||
names(): string[] { | ||
return ['grep']; | ||
constructor(wasmLoader: WasmLoader) { | ||
super(wasmLoader); | ||
} | ||
|
||
moduleName(): string { | ||
return 'grep'; | ||
} | ||
|
||
protected _getWasmModule(): any { | ||
return GrepModule.default; | ||
names(): string[] { | ||
return ['grep']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Loader of WASM modules. Once loaded, a module is cached so that it is faster to subsequently. | ||
* Must be run in a WebWorker. | ||
*/ | ||
export class WasmLoader { | ||
constructor(wasmBaseUrl?: string) { | ||
this._wasmBaseUrl = wasmBaseUrl ?? ''; | ||
} | ||
|
||
public getModule(name: string): any { | ||
let module = this._cache.get(name); | ||
if (module === undefined) { | ||
// Maybe should use @jupyterlab/coreutils.URLExt to combine URL components. | ||
const url = this._wasmBaseUrl + name + '.js'; | ||
console.log('Importing JS/WASM from ' + url); | ||
importScripts(url); | ||
module = (self as any).Module; | ||
this._cache.set(name, module); | ||
} | ||
return module; | ||
} | ||
|
||
private _wasmBaseUrl: string; | ||
private _cache = new Map<string, any>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters