@shopware-ag/dive 1.18.5-beta.2 → 1.18.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/build/dive.cjs +3856 -1
- package/build/dive.cjs.map +1 -1
- package/build/dive.js +24728 -6
- package/build/dive.js.map +1 -1
- package/build/src/ar/arquicklook/ARQuickLook.d.ts +2 -3
- package/build/src/com/Communication.d.ts +1 -4
- package/build/src/module/Module.d.ts +8 -0
- package/package.json +2 -2
- package/src/ar/arquicklook/ARQuickLook.ts +75 -48
- package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +45 -80
- package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -12
- package/src/com/Communication.ts +17 -84
- package/src/com/__test__/Communication.test.ts +43 -16
- package/src/module/Module.ts +45 -0
- package/src/module/__test__/Module.test.ts +54 -0
- package/build/AR-B-g0updz.js +0 -1450
- package/build/AR-B-g0updz.js.map +0 -1
- package/build/AR-BWQebw6-.cjs +0 -153
- package/build/AR-BWQebw6-.cjs.map +0 -1
- package/build/IO-BgiJzKrU.js +0 -1257
- package/build/IO-BgiJzKrU.js.map +0 -1
- package/build/IO-CuYml7Y5.cjs +0 -2
- package/build/IO-CuYml7Y5.cjs.map +0 -1
- package/build/MediaCreator-4zmvmUWH.js +0 -22
- package/build/MediaCreator-4zmvmUWH.js.map +0 -1
- package/build/MediaCreator-BNxZVYyZ.cjs +0 -2
- package/build/MediaCreator-BNxZVYyZ.cjs.map +0 -1
- package/build/TextureUtils-CxpuVgwF.js +0 -38
- package/build/TextureUtils-CxpuVgwF.js.map +0 -1
- package/build/TextureUtils-DNG-yR77.cjs +0 -19
- package/build/TextureUtils-DNG-yR77.cjs.map +0 -1
- package/build/dive-Mi8g8Khn.js +0 -24852
- package/build/dive-Mi8g8Khn.js.map +0 -1
- package/build/dive-_-yiZbhn.cjs +0 -3857
- package/build/dive-_-yiZbhn.cjs.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class DIVEModule<T> {
|
|
2
|
+
constructor(
|
|
3
|
+
private _path: string,
|
|
4
|
+
private _ctor: string,
|
|
5
|
+
) {}
|
|
6
|
+
|
|
7
|
+
private _promise: Promise<T> | null = null;
|
|
8
|
+
private _instance: T | null = null;
|
|
9
|
+
|
|
10
|
+
public async get(): Promise<T> {
|
|
11
|
+
// if we already have an instance, return it
|
|
12
|
+
if (this._instance) {
|
|
13
|
+
return Promise.resolve(this._instance);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// if we already have a loading process ongoing, return the already created promise
|
|
17
|
+
if (this._promise) {
|
|
18
|
+
return this._promise;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// if we don't have a promise yet, it means that we are not already loading the module
|
|
22
|
+
this._promise = (async () => {
|
|
23
|
+
const module = await import(this._path);
|
|
24
|
+
|
|
25
|
+
const ModuleConstructor = module[this._ctor];
|
|
26
|
+
|
|
27
|
+
if (!ModuleConstructor) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`DIVE: Module class ${this._ctor} not found in ${this._path}`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof ModuleConstructor !== 'function') {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`DIVE: Module at ${this._path} does not export a valid constructor (${this._ctor} wanted)`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this._instance = new ModuleConstructor() as T;
|
|
40
|
+
return this._instance;
|
|
41
|
+
})();
|
|
42
|
+
|
|
43
|
+
return this._promise;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DIVEModule } from '../Module';
|
|
2
|
+
|
|
3
|
+
jest.mock('/mock/path', () => mockModule, { virtual: true });
|
|
4
|
+
|
|
5
|
+
const mockModule: Record<string, any> = {};
|
|
6
|
+
|
|
7
|
+
describe('dive/module/DIVEModule', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
// Reset the mock module before each test
|
|
10
|
+
Object.keys(mockModule).forEach((key) => delete mockModule[key]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should return the same instance on multiple calls to get()', async () => {
|
|
14
|
+
mockModule.TestClass = class TestClass {};
|
|
15
|
+
const diveModule = new DIVEModule('/mock/path', 'TestClass');
|
|
16
|
+
|
|
17
|
+
const instance1 = await diveModule.get();
|
|
18
|
+
const instance2 = await diveModule.get();
|
|
19
|
+
|
|
20
|
+
expect(instance1).toBe(instance2);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should throw an error if the constructor is not found', async () => {
|
|
24
|
+
const diveModule = new DIVEModule('/mock/path', 'NonExistentClass');
|
|
25
|
+
|
|
26
|
+
await expect(diveModule.get()).rejects.toThrow(
|
|
27
|
+
'DIVE: Module class NonExistentClass not found in /mock/path',
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should throw an error if the constructor is not a function', async () => {
|
|
32
|
+
mockModule.InvalidClass = {};
|
|
33
|
+
const diveModule = new DIVEModule('/mock/path', 'InvalidClass');
|
|
34
|
+
|
|
35
|
+
await expect(diveModule.get()).rejects.toThrow(
|
|
36
|
+
'DIVE: Module at /mock/path does not export a valid constructor (InvalidClass wanted)',
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should only load the module once even with concurrent calls to get()', async () => {
|
|
41
|
+
mockModule.TestClass = class TestClass {};
|
|
42
|
+
const diveModule = new DIVEModule('/mock/path', 'TestClass');
|
|
43
|
+
|
|
44
|
+
const [
|
|
45
|
+
instance1,
|
|
46
|
+
instance2,
|
|
47
|
+
] = await Promise.all([
|
|
48
|
+
diveModule.get(),
|
|
49
|
+
diveModule.get(),
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
expect(instance1).toBe(instance2);
|
|
53
|
+
});
|
|
54
|
+
});
|