-
Notifications
You must be signed in to change notification settings - Fork 187
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
stash improvement ideas #3333
Comments
A big hurdle for using Stash as a plain client data store is the strict data types using EVM-based schemas, which limits storing things like JS native objects, using string keys, etc. We could lift out the performant bits of Stash (a strongly typed mutable object tree that uses tables with keys/records as its primary constraint) and then build the MUD Store-flavored version on top that turns Store config/tables into a more restricted set of data + helpers for working with it (i.e. encoding table names, keys). type Table = {
readonly [fieldName: string]: any;
};
type Tables = {
readonly [tableName: string]: Table;
}
type State<tables extends Tables> = {
readonly tables: tables;
readonly records: {
readonly [tableName in keyof tables]: {
readonly [key: string]: TableRecord<tables[tableName]>;
};
};
};
type MutableState<tables extends Tables> = {
// same as above, but mutable
};
type Stash<tables extends Tables> = {
state: MutableState<tables>
}; Note that this would mean flattening the current Stash internal representation from |
Thinking more on the useRecord({ stash, table, key })
useRecords({ stash, table })
useRecords({ stash, table, keys }) |
Some observations from my side:
|
Just realized that the current Might be nice to have an alternative hook to opt into updates if you need em. |
collapse
getRecord
andgetRecords
into a singleget
function that has a few optional parameters (e.g.key
orkeys
)could even collapse further if
get
returned a selector likeas a general rule, provide helpers to simplify usage/ergonomics that lead to data patterns we can optimize well (see below about shallow equality checks), but still allow for raw selectors for folks that want more advanced use and are willing to do the optimization themselves
consider defaulting to shallow equality check to avoid passing in an equality fn when getting records by keys, because this always returns a new object and won't pass the strict equality (
===
) checkadd stash context/provider for setting global defaults
useStash((state) => ...)
or with aboveget
selector likeuseStash(get(...))
The text was updated successfully, but these errors were encountered: