-
Notifications
You must be signed in to change notification settings - Fork 28
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: add asCallsOnlyArg to reduce size of metadata #149
Conversation
true | ||
); | ||
|
||
it('Metadata should decrease in byte size when `asCallsOnlyArg` is true with `createMetadataUnmemoized`', () => { |
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.
For the curious the reason we are testing both the unmemoized and memoized createMetadata
is because if the length option for memoizee
is changed to less than 3 the function will break for the asCallsOnlyArg
, but createMetadataUnmemoized
will still work with asCallsOnlyArg
. I wanted to isolate them both so we can make sure in the future if any changes are made to either it still works as is for both.
*/ | ||
export const createMetadata = memoizee(createMetadataUnmemoized, { | ||
length: 2, | ||
length: 3, |
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.
briefly reading over the docs (https://github.com/medikoo/memoizee#arguments-length), I wonder if this would work: "Dynamic length behavior can be forced by setting length to false, that means memoize will work with any number of arguments."
I am also a little confused how default args work in terms of length because of this note "Parameters predefined with default values (ES2015+ feature) are not reflected in function's length, therefore if you want to memoize them as well, you need to tweak length setting accordingly".
Either way though sounds like this works, so maybe not worth looking into
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.
It works with both false
, and length 3 🤔 . false
being more flexible, and 3
being strict but with a default arg. I do like the the idea of being strict with 3 though.
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.
lgtm - feel free to request me again when you update the examples
Co-authored-by: Zeke Mostov <z.mostov@gmail.com>
…ore into tarik-asCallsOnly
const { metadataRpc, registry } = options; | ||
registry.setMetadata(createMetadata(registry, metadataRpc)); | ||
const { metadataRpc, registry, asCallsOnlyArg } = options; | ||
registry.setMetadata(createMetadata(registry, metadataRpc, asCallsOnlyArg)); |
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.
Nit/Question: Why the suffix "Arg"?
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.
The idea being that asCallsOnly
is the name of the getter for the metadata in polkadot-js so I wanted to make it have a separate name to reduce confusion.
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.
Thanks for the explanation!
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.
Looks sane to me offhand :)
@@ -45,7 +45,26 @@ async function main(): Promise<void> { | |||
'state_getRuntimeVersion' | |||
); | |||
|
|||
// Create Polkadot's type registry. | |||
/** | |||
* Create Polkadot's type registry. |
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.
@emostov This is what i wrote for the examples. Let me know if you think there should be more than this.
rel: #111
adds
asCallsOnlyArg
as an option forgetRegistryBase
to reduce the size of the metadata.Todo: