1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix stale data

- The behaviour of asyncComputed is to not redo the call on every
  change between UNOBSERVED and OBSERVED

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-02-21 16:19:07 -05:00
parent 63a3e41d71
commit 7bcce5cb98

View File

@ -32,11 +32,14 @@ import activeThemeInjectable from "../../../../themes/active.injectable";
import type { ToHelmRelease } from "../../to-helm-release.injectable"; import type { ToHelmRelease } from "../../to-helm-release.injectable";
import toHelmReleaseInjectable from "../../to-helm-release.injectable"; import toHelmReleaseInjectable from "../../to-helm-release.injectable";
import { asyncComputed } from "@ogre-tools/injectable-react"; import { asyncComputed } from "@ogre-tools/injectable-react";
import targetHelmReleaseInjectable from "../target-helm-release.injectable";
const releaseDetailsModelInjectable = getInjectable({ const releaseDetailsModelInjectable = getInjectable({
id: "release-details-model", id: "release-details-model",
instantiate: (di, targetRelease: TargetHelmRelease) => { instantiate: (di, targetRelease: TargetHelmRelease) => {
const detailsHelmRelease = di.inject(targetHelmReleaseInjectable);
const model = new ReleaseDetailsModel({ const model = new ReleaseDetailsModel({
requestDetailedHelmRelease: di.inject(requestDetailedHelmReleaseInjectable), requestDetailedHelmRelease: di.inject(requestDetailedHelmReleaseInjectable),
targetRelease, targetRelease,
@ -51,9 +54,17 @@ const releaseDetailsModelInjectable = getInjectable({
toHelmRelease: di.inject(toHelmReleaseInjectable), toHelmRelease: di.inject(toHelmReleaseInjectable),
}); });
return asyncComputed({ return asyncComputed<ReleaseDetailsModel>({
getValueFromObservedPromise: async () => { getValueFromObservedPromise: async () => {
await model.load(); const currentHelmRelease = detailsHelmRelease.get();
if (
currentHelmRelease
&& currentHelmRelease.name === targetRelease.name
&& currentHelmRelease.namespace === targetRelease.namespace
) {
await model.load();
}
return model; return model;
}, },