diff --git a/packages/technical-features/messaging/computed-channel/index.ts b/packages/technical-features/messaging/computed-channel/index.ts index 4516e0b9a6..dd72ecf71b 100644 --- a/packages/technical-features/messaging/computed-channel/index.ts +++ b/packages/technical-features/messaging/computed-channel/index.ts @@ -6,7 +6,4 @@ export { export type { ChannelObserver, ComputedChannelFactory, - JsonifiableObject, - JsonifiableArray, - Jsonifiable, } from "./src/computed-channel/computed-channel.injectable"; diff --git a/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel-administration-channel.injectable.ts b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel-administration-channel.injectable.ts index b0fdb3c59f..da8dd4110a 100644 --- a/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel-administration-channel.injectable.ts +++ b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel-administration-channel.injectable.ts @@ -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"; diff --git a/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts index 03f5a16aab..b652a0c795 100644 --- a/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts +++ b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts @@ -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 = ( channel: MessageChannel, pendingValue: T, @@ -29,14 +23,12 @@ export const computedChannelInjectionToken = getInjectionToken = { +export type ChannelObserver = { channel: MessageChannel; observer: IComputedValue; }; -export const computedChannelObserverInjectionToken = getInjectionToken< - ChannelObserver ->({ +export const computedChannelObserverInjectionToken = getInjectionToken>({ 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}`, diff --git a/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx index 4736fe22d4..b1c648176d 100644 --- a/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx +++ b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx @@ -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 () => {