All files / src/core illusion-service.ts

93.94% Statements 31/33
91.67% Branches 11/12
100% Functions 4/4
93.94% Lines 31/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 331x 1x 1x 41x 41x 41x 41x 41x 41x 98x 33x 33x 33x 33x 33x 429x 429x 33x 33x     33x 33x 33x 33x 33x 33x 98x 98x 98x 41x 1x 1x
import Module from '../wasm/illusion.js';
import fileData from '../wasm/illusion.data';
 
export class IllusionService {
    private initPromise!: Promise<IllusionModule>;
    public module!: IllusionModule;
    public inWorker?: boolean;
 
    init(): Promise<IllusionModule> {
        if(!this.initPromise) {
            this.initPromise = Module({
                getPreloadedPackage: (packageName: string) => {
                    if(packageName.includes('illusion.data')) {
                        const list = [];
                        for(let i = 0; i < fileData.length; i++) {
                            list.push(fileData.charCodeAt(i));
                        }
                        return (new Uint8Array(list)).buffer;
                    }
                    return '';
                }
            })
                .then((module: IllusionModule) => {
                    this.module = module;
                    return module;
                });
        }
 
        return this.initPromise;
    }
}
 
export const illusionService = new IllusionService();