Skip to content

Commit

Permalink
New stores pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Nov 28, 2023
1 parent 9b8e640 commit 909bc60
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 110 deletions.
4 changes: 2 additions & 2 deletions .hc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/tmp/nix-shell.ApOFsz/5KjOe8iNe5iVwFbsAEWm8
/tmp/nix-shell.ApOFsz/iv8MJFw8Xq5ntkyXxj-EC
/tmp/nix-shell.3VqZ6c/GFgWpDW5ORfo45Iu-XQaI
/tmp/nix-shell.3VqZ6c/z0_HkroFusuerN55z0I1x
32 changes: 16 additions & 16 deletions flake.lock

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

128 changes: 67 additions & 61 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions tests/src/cancellation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ test('create and delete Cancellation', async () => {
let cancellactionsFor = await toPromise(
alice.store.cancellationsFor.get(cancelledHash).live
);
assert.equal(cancellactionsFor.length, 0);
assert.equal(cancellactionsFor.size, 0);

let undoneCancellactionsFor = await toPromise(
alice.store.cancellationsFor.get(cancelledHash).undone
);
assert.equal(undoneCancellactionsFor.length, 0);
assert.equal(undoneCancellactionsFor.size, 0);

// Alice creates a Cancellation
const cancellation: EntryRecord<Cancellation> =
Expand All @@ -126,15 +126,15 @@ test('create and delete Cancellation', async () => {
cancellactionsFor = await toPromise(
alice.store.cancellationsFor.get(cancelledHash).live
);
assert.equal(cancellactionsFor.length, 1);
assert.equal(cancellactionsFor.size, 1);

// Alice deletes the Cancellation
await alice.store.client.undoCancellation(cancellation.actionHash);

cancellactionsFor = await toPromise(
alice.store.cancellationsFor.get(cancelledHash).live
);
assert.equal(cancellactionsFor.length, 0);
assert.equal(cancellactionsFor.size, 0);

// Wait for the created entry to be propagated to the other node.
await dhtSync([alice.player, bob.player], alice.player.cells[0].cell_id[0]);
Expand All @@ -153,6 +153,6 @@ test('create and delete Cancellation', async () => {
undoneCancellactionsFor = await toPromise(
alice.store.cancellationsFor.get(cancelledHash).undone
);
assert.equal(undoneCancellactionsFor.length, 1);
assert.equal(undoneCancellactionsFor.size, 1);
});
});
6 changes: 3 additions & 3 deletions ui/custom-elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
"name": "getCancellationsFor",
"return": {
"type": {
"text": "Promise<Array<ActionHash>>"
"text": "Promise<Array<Link>>"
}
},
"parameters": [
Expand All @@ -283,7 +283,7 @@
"name": "getUndoneCancellationsFor",
"return": {
"type": {
"text": "Promise<Array<[CreateLink, Array<SignedActionHashed<DeleteLink>>]>>"
"text": "Promise<\n Array<\n [SignedActionHashed<CreateLink>, Array<SignedActionHashed<DeleteLink>>]\n >\n >"
}
},
"parameters": [
Expand Down Expand Up @@ -342,7 +342,7 @@
{
"kind": "field",
"name": "cancellationsFor",
"default": "new LazyHoloHashMap((cancelledHash: ActionHash) => ({\n live: pipe(\n liveLinksTargetsStore(\n this.client,\n cancelledHash,\n () => this.client.getCancellationsFor(cancelledHash),\n 'Cancellations'\n ),\n hashes => slice(this.cancellations, hashes)\n ),\n undone: pipe(\n deletedLinksTargetsStore(\n this.client,\n cancelledHash,\n () => this.client.getUndoneCancellationsFor(cancelledHash),\n 'Cancellations'\n ),\n linksDeleted =>\n slice(\n this.cancellations,\n linksDeleted.map(([cl]) => cl.target_address)\n )\n ),\n }))"
"default": "new LazyHoloHashMap((cancelledHash: ActionHash) => ({\n live: pipe(\n liveLinksStore(\n this.client,\n cancelledHash,\n () => this.client.getCancellationsFor(cancelledHash),\n 'Cancellations'\n ),\n links =>\n slice(\n this.cancellations,\n links.map(l => l.target)\n )\n ),\n undone: pipe(\n deletedLinksStore(\n this.client,\n cancelledHash,\n () => this.client.getUndoneCancellationsFor(cancelledHash),\n 'Cancellations'\n ),\n linksDeleted =>\n slice(\n this.cancellations,\n linksDeleted.map(([cl]) => cl.hashed.content.target_address)\n )\n ),\n }))"
},
{
"kind": "field",
Expand Down
4 changes: 2 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@holochain-open-dev/cancellations",
"version": "0.3.0",
"version": "0.4.0",
"scripts": {
"start": "vite --clearScreen false --port $UI_PORT",
"build": "npm run lint && tsc && npm run analyze -- --exclude dist",
Expand All @@ -27,7 +27,7 @@
"@holochain/client": "^0.16.0",
"@holochain-open-dev/elements": "^0.8.2",
"@holochain-open-dev/profiles": "^0.17.1",
"@holochain-open-dev/stores": "^0.7.11",
"@holochain-open-dev/stores": "^0.8.2",
"@holochain-open-dev/utils": "^0.16.2",
"@lit/context": "^1.0.0",
"@lit/localize": "^0.12.0",
Expand Down
10 changes: 7 additions & 3 deletions ui/src/cancellations-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CreateLink,
Delete,
DeleteLink,
HoloHash,
Link,
Record,
SignedActionHashed,
} from '@holochain/client';
Expand Down Expand Up @@ -69,13 +69,17 @@ export class CancellationsClient extends ZomeClient<CancellationsSignal> {
return new EntryRecord(record);
}

getCancellationsFor(actionHash: ActionHash): Promise<Array<ActionHash>> {
getCancellationsFor(actionHash: ActionHash): Promise<Array<Link>> {
return this.callZome('get_cancellations_for', actionHash);
}

getUndoneCancellationsFor(
actionHash: ActionHash
): Promise<Array<[CreateLink, Array<SignedActionHashed<DeleteLink>>]>> {
): Promise<
Array<
[SignedActionHashed<CreateLink>, Array<SignedActionHashed<DeleteLink>>]
>
> {
return this.callZome('get_undone_cancellations_for', actionHash);
}

Expand Down
Loading

0 comments on commit 909bc60

Please sign in to comment.