-
Notifications
You must be signed in to change notification settings - Fork 184
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
fix(store): do not render push and pop for static arrays, use static length [M-02] #2175
Conversation
🦋 Changeset detectedLatest commit: dabf602 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/store/ts/codegen/field.ts
Outdated
renderWithStore( | ||
storeArgument, | ||
({ _typedStore, _store, _commentSuffix, _methodNamePrefix }) => ` | ||
if (field.typeWrappingData && field.typeWrappingData.kind === "staticArray") { |
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.
I don't love this check as is, we repeat it for pop
and push
, then again for length
.
It's also weird to treat static arrays as dynamic with the if (field.isDynamic)
check, but then differentiate them using this.
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.
curious if @dk1a has any insight into this
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.
terminology is weird here
isDynamic
, as well as dynamic and static table fields is a mud-specific thing
A better name for isDynamic
might be isNonPrimitive
- it indicates any array or struct
The word static
in static arrays is used in an unrelated context, taken from solidity
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.
#1668 is related, I also don't like how hacky this check is, especially since now it's used in more places
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.
good enough imo!
only thing I can think of that might help make this easier to understand is separate how we codegen dynamic vs static fields, but not sure if it's worth it here (we'll do a bigger refactor pass later)
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.
did a quick indent change to match other parts of the codebase, because it was hard to explain over text
need to add a changeset but otherwise lgtm!
Static arrays are now treated differently to dynamic arrays:
push
andpop
methods should not be used in static arrays so they are not rendered.length
method now returns the hardcoded known length.