mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: move PlatformSpecific back to core
- This is needed in 6.4 and this will make that transition easier Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
0bc3d9f8b2
commit
75a1b0a983
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DiContainerForInjection, InjectionToken } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import platformInjectable from "../vars/platform.injectable";
|
||||
|
||||
export interface PlatformSpecific<T> {
|
||||
instantiate: () => T;
|
||||
readonly platform: NodeJS.Platform;
|
||||
}
|
||||
|
||||
const platformSpecificVersionInjectable = getInjectable({
|
||||
id: "platform-specific-version",
|
||||
instantiate: (di: DiContainerForInjection) => {
|
||||
const targetPlatform = di.inject(platformInjectable);
|
||||
|
||||
return <T>(token: InjectionToken<PlatformSpecific<T>, void>) => {
|
||||
const impls = di.injectMany(token);
|
||||
|
||||
const impl = impls.find(impl => impl.platform === targetPlatform);
|
||||
|
||||
if (!impl) {
|
||||
throw new Error(`No platform specific implementation of "${token.id}" found`);
|
||||
}
|
||||
|
||||
return impl.instantiate();
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default platformSpecificVersionInjectable;
|
||||
|
||||
@ -29,7 +29,6 @@ export * from "./src/noop";
|
||||
export * from "./src/object";
|
||||
export * from "./src/observable-crate";
|
||||
export * from "./src/on-keyboard-shortcut";
|
||||
export * from "./src/platform-specific-version"
|
||||
export * from "./src/prevDefault";
|
||||
export * from "./src/readableStream";
|
||||
export * from "./src/readonly";
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export interface PlatformSpecific<T> {
|
||||
instantiate: () => T;
|
||||
readonly platform: NodeJS.Platform | "<default>";
|
||||
}
|
||||
|
||||
export const getPlatformSpecificFor = (targetPlatform: NodeJS.Platform, id: string) => <T>(specificImplementations: PlatformSpecific<T>[]): T => {
|
||||
const impl = specificImplementations.find(impl => impl.platform === targetPlatform)
|
||||
?? specificImplementations.find(impl => impl.platform === "<default>");
|
||||
|
||||
if (!impl) {
|
||||
throw new Error(`No platform specific implementation of "${id}" found`);
|
||||
}
|
||||
|
||||
return impl.instantiate();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user