From c2ff882b8ebbbc98965ac4efad3cae540d820ca4 Mon Sep 17 00:00:00 2001 From: "guillem.cordoba" Date: Wed, 17 Apr 2024 17:16:49 +0200 Subject: [PATCH] Attempt to fix bug --- nix/sweettest.nix | 1 - packages/stores/package.json | 2 +- packages/stores/src/holochain.ts | 13 +++++++++++++ packages/stores/tests/holochain.test.js | 21 +++++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/nix/sweettest.nix b/nix/sweettest.nix index d8bb84c..2c3b6f4 100644 --- a/nix/sweettest.nix +++ b/nix/sweettest.nix @@ -57,6 +57,5 @@ in craneLib.cargoNextest (commonArgs // { inherit cargoArtifacts; cargoNextestExtraArgs = "-p ${crate} --locked -j 1"; - DNA_PATH = dna; }) diff --git a/packages/stores/package.json b/packages/stores/package.json index 792c1d2..d9d5c3a 100644 --- a/packages/stores/package.json +++ b/packages/stores/package.json @@ -1,6 +1,6 @@ { "name": "@holochain-open-dev/stores", - "version": "0.300.0-dev.3", + "version": "0.300.0-dev.4", "description": "Re-export of svelte/store, with additional utilities to build reusable holochain-open-dev modules", "author": "guillem.cordoba@gmail.com", "main": "dist/index.js", diff --git a/packages/stores/src/holochain.ts b/packages/stores/src/holochain.ts index 68331bf..e8f1733 100644 --- a/packages/stores/src/holochain.ts +++ b/packages/stores/src/holochain.ts @@ -65,6 +65,7 @@ export function collectionStore< let links: Link[]; const maybeSet = (newLinksValue: Link[]) => { + if (!active) return; const orderedNewLinks = uniquifyLinks(newLinksValue).sort( sortLinksByTimestampAscending ); @@ -81,6 +82,7 @@ export function collectionStore< }; const fetch = async () => { + if (!active) return; const nlinks = await fetchCollection().finally(() => { if (active) { setTimeout(() => fetch(), pollIntervalMs); @@ -177,6 +179,7 @@ export function latestVersionOfEntryStore< let active = true; let latestVersion: EntryRecord | undefined; const fetch = async () => { + if (!active) return; try { const nlatestVersion = await fetchLatestVersion(); if (nlatestVersion) { @@ -209,6 +212,7 @@ export function latestVersionOfEntryStore< }; fetch(); const unsubs = client.onSignal((originalSignal) => { + if (!active) return; if (!(originalSignal as ActionCommittedSignal).type) return; const signal = originalSignal as ActionCommittedSignal; @@ -262,6 +266,8 @@ export function allRevisionsOfEntryStore< let active = true; let allRevisions: Array>; const fetch = async () => { + if (!active) return; + const nAllRevisions = await fetchAllRevisions().finally(() => { if (active) { setTimeout(() => fetch(), pollIntervalMs); @@ -280,6 +286,7 @@ export function allRevisionsOfEntryStore< }; await fetch(); const unsubs = client.onSignal(async (originalSignal) => { + if (!active) return; if (!(originalSignal as ActionCommittedSignal).type) return; const signal = originalSignal as ActionCommittedSignal; @@ -333,6 +340,7 @@ export function deletesForEntryStore< let active = true; let deletes: Array>; const fetch = async () => { + if (!active) return; const ndeletes = await fetchDeletes().finally(() => { if (active) { setTimeout(() => fetch(), pollIntervalMs); @@ -351,6 +359,7 @@ export function deletesForEntryStore< }; await fetch(); const unsubs = client.onSignal((originalSignal) => { + if (!active) return; if (!(originalSignal as ActionCommittedSignal).type) return; const signal = originalSignal as ActionCommittedSignal; @@ -450,6 +459,7 @@ export function liveLinksStore< let active = true; const maybeSet = (newLinksValue: Link[]) => { + if (!active) return; const orderedNewLinks = uniquifyLinks(newLinksValue).sort( sortLinksByTimestampAscending ); @@ -466,6 +476,7 @@ export function liveLinksStore< } }; const fetch = async () => { + if (!active) return; const nlinks = await fetchLinks().finally(() => { if (active) { setTimeout(() => fetch(), pollIntervalMs); @@ -550,6 +561,7 @@ export function deletedLinksStore< [SignedActionHashed, Array>] > ) => { + if (!active) return; const orderedNewLinks = newDeletedLinks.sort( sortDeletedLinksByTimestampAscending ); @@ -579,6 +591,7 @@ export function deletedLinksStore< } }; const fetch = async () => { + if (!active) return; const ndeletedLinks = await fetchDeletedLinks().finally(() => { if (active) { setTimeout(() => fetch(), pollIntervalMs); diff --git a/packages/stores/tests/holochain.test.js b/packages/stores/tests/holochain.test.js index a194760..8b9a572 100644 --- a/packages/stores/tests/holochain.test.js +++ b/packages/stores/tests/holochain.test.js @@ -84,6 +84,27 @@ test("liveLinks only updates once if no new links exist", async () => { }); }); +test("liveLinks makes the request again after being unsubscribed from", async () => { + const links = [await fakeLink()]; + let requests = 0; + const store = liveLinksStore( + new ZomeClient(new ZomeMock("", "")), + await fakeEntryHash(), + async () => { + requests += 1; + return links; + }, + "" + ); + + await toPromise(store); + await toPromise(store); + await toPromise(store); + await toPromise(store); + + assert.equal(requests, 4) +}); + test("collection store works", async () => { const links = [await fakeLink()]; const collection = collectionStore(