mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove BaseStore<T> and replace with composition of dependencies (#7002)
* Rename ExtensionStore -> BaseExtensionStore - The name was too close to ExtensionsStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move ExtensionsStore to new format Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move ClusterStore to new format Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move UserStore to new format Signed-off-by: Sebastian Malton <sebastian@malton.name> * Cleanup types to remove multiple cast locations Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move HotbarStore to new format Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move WeblinkStore to new format Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move FileSystemProvisionerStore to new format Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Clean up impl and rename to better describe intent Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix remaining type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fully split apart the enabled extensions storage Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fully split apart the clusters storage Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fully split apart the hotbar storage Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fully split apart the weblinks storage Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fully split apart the user preferences storage Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix crashing Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests and snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix integration test failures Signed-off-by: Sebastian Malton <sebastian@malton.name> * Improve typing to prevent errors in the future. Signed-off-by: Sebastian Malton <sebastian@malton.name> * Cleanup @k8slens/messaging and friends - To fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint issue Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix global override not being complete enough causing tests to fail Signed-off-by: Sebastian Malton <sebastian@malton.name> * Bump memory for unit tests on CI Signed-off-by: Sebastian Malton <sebastian@malton.name> * Attempt to fix memory issue on CI again Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixup test because of new injectables Signed-off-by: Sebastian Malton <sebastian@malton.name> * Upgrade Jest Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix unit tests falling over Signed-off-by: Sebastian Malton <sebastian@malton.name> * Back out jest config change Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove console log Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshot Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests by matching equality instead of snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests by forcing specific snapshot style - Ubuntu CI seems to format arrays in snapshots differently than macOS locally Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
ba4a283af9
commit
49f0a1af9c
365 files changed
+6733
-3972
No files matched your search
+31
-24
@@ -1,5 +1,11 @@
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import type { Channel, MessageChannelHandler, RequestChannelHandler } from "@k8slens/messaging";
|
||||
import type {
|
||||
MessageChannel,
|
||||
MessageChannelHandler,
|
||||
MessageChannelListener,
|
||||
RequestChannel,
|
||||
RequestChannelHandler,
|
||||
} from "@k8slens/messaging";
|
||||
|
||||
import {
|
||||
enlistMessageChannelListenerInjectionToken,
|
||||
@@ -20,6 +26,8 @@ export type MessageBridgeFake = {
|
||||
setAsync: (value: boolean) => void;
|
||||
};
|
||||
|
||||
type MessageHandlers = Set<MessageChannelHandler<MessageChannel<any>>>;
|
||||
|
||||
const overrideMessaging = ({
|
||||
di,
|
||||
messageListenersByDi,
|
||||
@@ -28,13 +36,13 @@ const overrideMessaging = ({
|
||||
}: {
|
||||
di: DiContainer;
|
||||
|
||||
messageListenersByDi: Map<DiContainer, Map<string, Set<MessageChannelHandler<Channel>>>>;
|
||||
messageListenersByDi: Map<DiContainer, Map<string, MessageHandlers>>;
|
||||
|
||||
messagePropagationBuffer: Set<{ resolve: () => Promise<void> }>;
|
||||
|
||||
getAsyncModeStatus: () => boolean;
|
||||
}) => {
|
||||
const messageHandlersByChannel = new Map<string, Set<MessageChannelHandler<Channel>>>();
|
||||
const messageHandlersByChannel = new Map<string, MessageHandlers>();
|
||||
|
||||
messageListenersByDi.set(di, messageHandlersByChannel);
|
||||
|
||||
@@ -64,30 +72,36 @@ const overrideMessaging = ({
|
||||
});
|
||||
});
|
||||
|
||||
di.override(enlistMessageChannelListenerInjectionToken, () => (listener) => {
|
||||
if (!messageHandlersByChannel.has(listener.channel.id)) {
|
||||
messageHandlersByChannel.set(listener.channel.id, new Set());
|
||||
}
|
||||
di.override(
|
||||
enlistMessageChannelListenerInjectionToken,
|
||||
() =>
|
||||
<T>(listener: MessageChannelListener<MessageChannel<T>>) => {
|
||||
if (!messageHandlersByChannel.has(listener.channel.id)) {
|
||||
messageHandlersByChannel.set(listener.channel.id, new Set());
|
||||
}
|
||||
|
||||
const handlerSet = messageHandlersByChannel.get(listener.channel.id);
|
||||
const handlerSet = messageHandlersByChannel.get(listener.channel.id);
|
||||
|
||||
handlerSet?.add(listener.handler);
|
||||
handlerSet?.add(listener.handler);
|
||||
|
||||
return () => {
|
||||
handlerSet?.delete(listener.handler);
|
||||
};
|
||||
});
|
||||
return () => {
|
||||
handlerSet?.delete(listener.handler);
|
||||
};
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
type RequestHandlers = Set<RequestChannelHandler<RequestChannel<any, any>>>;
|
||||
|
||||
const overrideRequesting = ({
|
||||
di,
|
||||
requestListenersByDi,
|
||||
}: {
|
||||
di: DiContainer;
|
||||
|
||||
requestListenersByDi: Map<DiContainer, Map<string, Set<RequestChannelHandler<Channel>>>>;
|
||||
requestListenersByDi: Map<DiContainer, Map<string, RequestHandlers>>;
|
||||
}) => {
|
||||
const requestHandlersByChannel = new Map<string, Set<RequestChannelHandler<Channel>>>();
|
||||
const requestHandlersByChannel = new Map<string, RequestHandlers>();
|
||||
|
||||
requestListenersByDi.set(di, requestHandlersByChannel);
|
||||
|
||||
@@ -141,15 +155,8 @@ const overrideRequesting = ({
|
||||
};
|
||||
|
||||
export const getMessageBridgeFake = (): MessageBridgeFake => {
|
||||
const messageListenersByDi = new Map<
|
||||
DiContainer,
|
||||
Map<string, Set<MessageChannelHandler<Channel>>>
|
||||
>();
|
||||
|
||||
const requestListenersByDi = new Map<
|
||||
DiContainer,
|
||||
Map<string, Set<RequestChannelHandler<Channel>>>
|
||||
>();
|
||||
const messageListenersByDi = new Map<DiContainer, Map<string, MessageHandlers>>();
|
||||
const requestListenersByDi = new Map<DiContainer, Map<string, RequestHandlers>>();
|
||||
|
||||
const messagePropagationBuffer = new Set<AsyncFnMock<() => void>>();
|
||||
|
||||
|
||||
Reference in new issue
Block a user