Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(guides/hello/filter): update for app namespace 🚗 #2858

Merged
merged 6 commits into from
May 23, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions docs/pages/guides/hello-world/filter-sync.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Edit `packages/client/src/mud/setupNetwork.ts`.

<CollapseCode>

```ts filename="setupNetwork.ts" copy showLineNumbers {24-25,95-107}
```ts filename="setupNetwork.ts" copy showLineNumbers {23-24,94-106}
/*
* The MUD client code is built on top of viem
* (https://viem.sh/docs/getting-started.html).
Expand All @@ -35,7 +35,6 @@ import {
http,
createWalletClient,
Hex,
parseEther,
ClientConfig,
getContract,
} from "viem";
Expand Down Expand Up @@ -119,14 +118,14 @@ export async function setupNetwork() {
startBlock: BigInt(networkConfig.initialBlockNumber),
filters: [
{
tableId: resourceToHex({ type: "table", namespace: "", name: "Counter" }),
tableId: config.tables.app__Counter.tableId
},
{
tableId: resourceToHex({ type: "table", namespace: "", name: "History" }),
tableId: resourceToHex({ type: "table", namespace: "app", name: "History" }),
key0: pad("0x01"),
},
{
tableId: resourceToHex({ type: "table", namespace: "", name: "History" }),
tableId: resourceToHex({ type: "table", namespace: "app", name: "History" }),
qbzzt marked this conversation as resolved.
Show resolved Hide resolved
key0: pad("0x05"),
},
],
Expand All @@ -150,7 +149,7 @@ export async function setupNetwork() {
</CollapseCode>

Click **Increment** a few times to see you only see the history for counter values 1 and 5.
You can also go to the MUD Dev Tools and see that when you select **Components > History** it only has those lines.
You can also go to the MUD Dev Tools and see that when you select **Components > app\_\_History** it only has those lines.

### Explanation

Expand All @@ -170,21 +169,21 @@ Each filter is a structure that can have up to three fields, and all the fields
```ts
filters: [
{
tableId: resourceToHex({ type: "table", namespace: "", name: "Counter"}),
tableId: resourceToHex({ type: "table", namespace: "app", name: "Counter"}),
},
```

The first filter is for the `:Counter` table (`Counter` in the root namespace).
The first filter is for the `app__Counter` table (`Counter` in the `app` namespace).
We don't specify any keys, because we want all the rows of the table.
It's a singleton so there is only one row anyway.

```ts
{
tableId: resourceToHex({ type: "table", namespace: "", name: "History"}),
tableId: resourceToHex({ type: "table", namespace: "app", name: "History"}),
key0: pad("0x01"),
},
{
tableId: resourceToHex({ type: "table", namespace: "", name: "History"}),
tableId: resourceToHex({ type: "table", namespace: "app", name: "History"}),
key0: pad("0x05"),
},
],
Expand Down
Loading