-
Notifications
You must be signed in to change notification settings - Fork 205
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
feat: sync data to store cache, decode keys #808
Conversation
packages/std-client/package.json
Outdated
@@ -42,6 +42,7 @@ | |||
"@latticexyz/recs": "workspace:*", | |||
"@latticexyz/solecs": "workspace:*", | |||
"@latticexyz/store": "workspace:*", | |||
"@latticexyz/store-cache": "workspace:^", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what command are you using to add this? wondering if we should just make them all ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this happens when i do pnpm add @latticexyz/store-cache
faebbeb
to
52b1d01
Compare
@@ -7,17 +7,19 @@ import { world } from "./world"; | |||
import { Contract, Signer, utils } from "ethers"; | |||
import { JsonRpcProvider } from "@ethersproject/providers"; | |||
import { IWorld__factory } from "contracts/types/ethers-contracts/factories/IWorld__factory"; | |||
import storeConfig from "../../../contracts/mud.config"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might break vercel deployments because it's outside the client directory. Is there an easy workaround?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you import storeConfig from "contracts/mud.config"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that worked!
useEffect(() => { | ||
storeCache.tables.Inventory.subscribe((update) => console.log("got update from inventory table", update)); | ||
}, [storeCache]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
planning to add a better example for this in a follow up once we have a scan
support to get multiple rows of a table
|
||
export default mudConfig({ | ||
namespace: "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this the default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is, good catch! added this in some intermediate version where importing mudConfig
didn't work yet
primaryKeys: { | ||
user: "address", | ||
item: "bytes32", | ||
variant: "uint32", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is variant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a random example of a uint32
key tuple (though of a variant of some item, like "red cup" vs "green cup", lemme know if you can think of a better example haha)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh, in that case, itemVariant
might be a little more descriptive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gonna revisit this in an immediate followup! (the example itself is not very expressive yet)
@@ -6,7 +6,7 @@ import { IStore } from "@latticexyz/store/types/ethers-contracts/IStore.sol/ISto | |||
|
|||
// worldAddress:tableId => schema | |||
// TODO: add chain ID to namespace? | |||
const schemaCache: Partial<Record<`${string}:${string}`, Promise<TableSchema>>> = {}; | |||
const schemaCache: Record<`${string}:${string}`, Promise<TableSchema>> = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason this changed?
I tend to use Partial<Record<...>>
for any object that I'm filling in over time, otherwise the types don't reflect that a key can sometimes not have a value (missing from object)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep agree this should be Partial
!
// defined in the local mud config) | ||
// (see https://github.com/latticexyz/mud/issues/824) | ||
|
||
// `Object.getOwnPropertyNames` guarantees key order, `Object.keys` does not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
NetworkEvent
streamstore-cache
as client data backend that allows interacting with the data with typed key tuples (data is still also stored torecs
,store-cache
is just an add-on for now)address
likeabi.encode
does (left padded) #817name
config option from tables #818