diff --git a/packages/runner/src/reactive-dependencies.ts b/packages/runner/src/reactive-dependencies.ts index 5a1443f32..e5c773ac3 100644 --- a/packages/runner/src/reactive-dependencies.ts +++ b/packages/runner/src/reactive-dependencies.ts @@ -150,10 +150,12 @@ export function determineTriggeredActions( if (i <= beforeLastObject) { beforeValues[i + 1] = (beforeValues[i] as Keyable)[targetPath[i]!]; if (isRecord(beforeValues[i + 1])) beforeLastObject = i + 1; + else beforeLastObject = i; } if (i <= afterLastObject) { afterValues[i + 1] = (afterValues[i] as Keyable)[targetPath[i]!]; if (isRecord(afterValues[i + 1])) afterLastObject = i + 1; + else afterLastObject = i; } } currentPath = targetPath; diff --git a/packages/runner/src/storage/transaction/journal.ts b/packages/runner/src/storage/transaction/journal.ts index 447a8e890..19253887d 100644 --- a/packages/runner/src/storage/transaction/journal.ts +++ b/packages/runner/src/storage/transaction/journal.ts @@ -109,18 +109,19 @@ export const read = ( if (error) { return { error }; } else { + // Track read activity with metadata + journal.state.activity.push({ + read: { + ...address, + space, + meta: options?.meta ?? {}, + }, + }); + const result = branch.read(address, options); if (result.error) { return { error: result.error.from(space) }; } else { - // Track read activity with metadata - journal.state.activity.push({ - read: { - ...address, - space, - meta: options?.meta ?? {}, - }, - }); return result; } } diff --git a/packages/runner/test/schema.test.ts b/packages/runner/test/schema.test.ts index 03869d200..9825faaf5 100644 --- a/packages/runner/test/schema.test.ts +++ b/packages/runner/test/schema.test.ts @@ -370,15 +370,25 @@ describe("Schema Support", () => { }); const log = txToReactivityLog(tx); const reads = sortAndCompactPaths(log.reads); - expect(reads.length).toEqual(3); - expect( - reads.map((r: IMemorySpaceAddress) => ({ id: r.id, path: r.path })) - .sort((a, b) => a.id.localeCompare(b.id)), - ).toEqual([ - { id: toURI(docCell.entityId!), path: ["current"] }, - { id: toURI(linkEntityId), path: [] }, - { id: toURI(initialEntityId), path: ["foo"] }, - ].sort((a, b) => a.id.localeCompare(b.id))); + console.log(reads); + expect(reads).toContainEqual({ + space, + id: toURI(linkEntityId), + path: [], + type: "application/json", + }); + expect(reads).toContainEqual({ + space, + id: toURI(docCell.entityId!), + path: ["current"], + type: "application/json", + }); + expect(reads).toContainEqual({ + space, + id: toURI(initialEntityId), + path: ["foo"], + type: "application/json", + }); // Then update it initial.withTx(tx).set({ foo: { label: "first - update" } }); @@ -405,7 +415,7 @@ describe("Schema Support", () => { await runtime.idle(); - (expect(rootValues) as any).toEqualIgnoringSymbols([ + expect(rootValues).toEqual([ "root", "cancelled", "root", @@ -418,7 +428,7 @@ describe("Schema Support", () => { await runtime.idle(); - (expect(rootValues) as any).toEqualIgnoringSymbols([ + expect(rootValues).toEqual([ "root", "cancelled", "root",