mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove requirement for JSON of messages (#7426)
* Remove requirement for JSON of messages - Remove backhanded requirements of reactive contexts, overriding application configurations. Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error Signed-off-by: Sebastian Malton <sebastian@malton.name> --------- Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
962aa13de2
commit
132c51018b
@ -6,7 +6,4 @@ export {
|
||||
export type {
|
||||
ChannelObserver,
|
||||
ComputedChannelFactory,
|
||||
JsonifiableObject,
|
||||
JsonifiableArray,
|
||||
Jsonifiable,
|
||||
} from "./src/computed-channel/computed-channel.injectable";
|
||||
|
||||
@ -1,15 +1,9 @@
|
||||
import { reaction } from "mobx";
|
||||
|
||||
import { getMessageChannelListenerInjectable } from "@k8slens/messaging";
|
||||
import { sendMessageToChannelInjectionToken } from "@k8slens/messaging";
|
||||
import type { JsonPrimitive } from "type-fest";
|
||||
import { computedChannelObserverInjectionToken } from "./computed-channel.injectable";
|
||||
import { getMessageChannel } from "@k8slens/messaging";
|
||||
|
||||
export type JsonifiableObject = { [Key in string]?: Jsonifiable } | { toJSON: () => Jsonifiable };
|
||||
export type JsonifiableArray = readonly Jsonifiable[];
|
||||
export type Jsonifiable = JsonPrimitive | JsonifiableObject | JsonifiableArray;
|
||||
|
||||
export type ComputedChannelAdminMessage = {
|
||||
channelId: string;
|
||||
status: "became-observed" | "became-unobserved";
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||
|
||||
import {
|
||||
_getGlobalState,
|
||||
computed,
|
||||
IComputedValue,
|
||||
observable,
|
||||
@ -13,13 +12,8 @@ import {
|
||||
import type { MessageChannel } from "@k8slens/messaging";
|
||||
import { getMessageChannelListenerInjectable } from "@k8slens/messaging";
|
||||
import { sendMessageToChannelInjectionToken } from "@k8slens/messaging";
|
||||
import type { JsonPrimitive } from "type-fest";
|
||||
import { computedChannelAdministrationChannel } from "./computed-channel-administration-channel.injectable";
|
||||
|
||||
export type JsonifiableObject = { [Key in string]?: Jsonifiable } | { toJSON: () => Jsonifiable };
|
||||
export type JsonifiableArray = readonly Jsonifiable[];
|
||||
export type Jsonifiable = JsonPrimitive | JsonifiableObject | JsonifiableArray;
|
||||
|
||||
export type ComputedChannelFactory = <T>(
|
||||
channel: MessageChannel<T>,
|
||||
pendingValue: T,
|
||||
@ -29,14 +23,12 @@ export const computedChannelInjectionToken = getInjectionToken<ComputedChannelFa
|
||||
id: "computed-channel-injection-token",
|
||||
});
|
||||
|
||||
export type ChannelObserver<T extends Jsonifiable> = {
|
||||
export type ChannelObserver<T> = {
|
||||
channel: MessageChannel<T>;
|
||||
observer: IComputedValue<T>;
|
||||
};
|
||||
|
||||
export const computedChannelObserverInjectionToken = getInjectionToken<
|
||||
ChannelObserver<Jsonifiable>
|
||||
>({
|
||||
export const computedChannelObserverInjectionToken = getInjectionToken<ChannelObserver<unknown>>({
|
||||
id: "computed-channel-observer",
|
||||
});
|
||||
|
||||
@ -49,19 +41,7 @@ const computedChannelInjectable = getInjectable({
|
||||
return ((channel, pendingValue) => {
|
||||
const observableValue = observable.box(pendingValue);
|
||||
|
||||
const computedValue = computed(() => {
|
||||
const { trackingDerivation } = _getGlobalState();
|
||||
|
||||
const contextIsReactive = !!trackingDerivation;
|
||||
|
||||
if (!contextIsReactive) {
|
||||
throw new Error(
|
||||
`Tried to access value of computed channel "${channel.id}" outside of reactive context. This is not possible, as the value is acquired asynchronously sometime *after* being observed. Not respecting that, the value could be stale.`,
|
||||
);
|
||||
}
|
||||
|
||||
return observableValue.get();
|
||||
});
|
||||
const computedValue = computed(() => observableValue.get());
|
||||
|
||||
const valueReceiverInjectable = getMessageChannelListenerInjectable({
|
||||
id: `computed-channel-value-receiver-for-${channel.id}`,
|
||||
|
||||
@ -292,14 +292,6 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
});
|
||||
});
|
||||
|
||||
it("when accessing the computed value outside of reactive context, throws", () => {
|
||||
expect(() => {
|
||||
computedTestChannel.get();
|
||||
}).toThrow(
|
||||
'Tried to access value of computed channel "some-channel-id" outside of reactive context. This is not possible, as the value is acquired asynchronously sometime *after* being observed. Not respecting that, the value could be stale.',
|
||||
);
|
||||
});
|
||||
|
||||
it("no value gets listened in di-1 anymore", () => {
|
||||
expect(latestValueMessage).toBeUndefined();
|
||||
});
|
||||
@ -381,14 +373,6 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("when accessing the computed value outside of reactive context, throws", () => {
|
||||
expect(() => {
|
||||
computedTestChannel.get();
|
||||
}).toThrow(
|
||||
'Tried to access value of computed channel "some-channel-id" outside of reactive context. This is not possible, as the value is acquired asynchronously sometime *after* being observed. Not respecting that, the value could be stale.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("given observation of unrelated computed channel is stopped, observation of other computed channel still works", async () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user