Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add static browserApi method getAllSharedLibNames #29

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/app/GlobalBrowserApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LifeCycles } from './interfaces/LifeCycles';
import { ParcelLifecycleFnProps } from './interfaces/ParcelLifecycleFnProps';
import { MountParcel } from './interfaces/MountParcel';
import { GetAllSharedLibNames } from './interfaces/GetAllSharedLibNames';

/**
* ILC exposes some utility APIs globally at `window.ILC`. Here we provide convenience typings to use with typescript.
Expand Down Expand Up @@ -56,4 +57,16 @@ export class GlobalBrowserApi {
static mountRootParcel: MountParcel = (parcelConfig, parcelProps) => {
return (window as any).ILC.mountRootParcel(parcelConfig, parcelProps);
};

/**
* Will return names of all registered shared libraries in ILC-Registry
*
* @example
* ```javascript
* const sharedLibNames = await ILC.getAllSharedLibNames();
* ```
*/
static getAllSharedLibNames: GetAllSharedLibNames = () => {
return (window as any).ILC.getAllSharedLibNames();
};
}
1 change: 1 addition & 0 deletions src/app/interfaces/GetAllSharedLibNames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type GetAllSharedLibNames = () => Promise<string[]>;
6 changes: 6 additions & 0 deletions test/app/GlobalBrowserApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('GlobalBrowserApi', () => {
navigate: () => 'navigate',
importParcelFromApp: () => Promise.resolve('importParcelFromApp'),
mountRootParcel: () => 'mountRootParcel',
getAllSharedLibNames: () => Promise.resolve(['libName_1', 'libName_2']),
},
};
});
Expand Down Expand Up @@ -48,4 +49,9 @@ describe('GlobalBrowserApi', () => {
domElement: (null as unknown) as HTMLElement,
});
});

it('getAllSharedLibNames is correctly typed and callable', async () => {
const res = await GlobalBrowserApi.getAllSharedLibNames();
expect(res).to.deep.eq(['libName_1', 'libName_2']);
});
});