Skip to content

Commit

Permalink
Bump version, latestState
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Feb 7, 2024
1 parent 8f27f0f commit 6b15578
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 38 deletions.
52 changes: 26 additions & 26 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@holochain-syn/store",
"version": "0.11.1",
"version": "0.11.2",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
Expand All @@ -16,8 +16,8 @@
"build:watch": "tsc -w --preserveWatchOutput"
},
"dependencies": {
"@holochain-open-dev/stores": "^0.8.9",
"@holochain-open-dev/utils": "^0.16.3",
"@holochain-open-dev/stores": "^0.8.11",
"@holochain-open-dev/utils": "^0.16.5",
"@holochain-syn/client": "^0.11.1",
"@holochain/client": "^0.16.1",
"@msgpack/msgpack": "^2.7.2",
Expand Down
1 change: 1 addition & 0 deletions packages/store/src/session-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ export class SessionStore<S, E> implements SliceStore<S, E> {
for (const interval of this.intervals) {
clearInterval(interval);
}
this.onLeave();
}

private handleNewParticipant(participant: AgentPubKey) {
Expand Down
19 changes: 19 additions & 0 deletions packages/store/src/workspace-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AsyncReadable,
AsyncStatus,
derived,
deriveStore,
liveLinksStore,
pipe,
retryUntilSuccess,
Expand Down Expand Up @@ -177,6 +178,24 @@ export class WorkspaceStore<S, E> {
)
);

/**
* Keeps an up to date copy of the state of the session if there is an active one,
* or the latest snapshot if there isn't a session
*/
latestState: AsyncReadable<S> = deriveStore(this.session, session => {
if (session)
return derived(
session.state,
s =>
({
status: 'complete',
value: s,
} as AsyncStatus<S>)
);

return this.latestSnapshot;
});

/**
* Joins the real-time collaborative session for this workspace
* This will connect to all the active peers and start to synchronize with them
Expand Down
8 changes: 8 additions & 0 deletions tests/src/lib/syn-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ test('SynStore, DocumentStore, WorkspaceStore and SessionStore work', async () =

assert.equal(participants.active.length, 1);

let latestState = await toPromise(aliceWorkspaceStore.latestState);

assert.deepEqual(latestState, state);

await aliceSessionStore.leaveSession();

latestState = await toPromise(aliceWorkspaceStore.latestState);

assert.deepEqual(latestState, state);
});
});

0 comments on commit 6b15578

Please sign in to comment.