-
Notifications
You must be signed in to change notification settings - Fork 9
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
Simplify/refactor fxparam (de)serializers/handlers #18
Conversation
Major simplifications of various fxparam related functions: - add U8/32/64 hex formatters - add asBytes() hexbyte string parser - add minmax() helper for enforcing optional ranges and dedupe logic - update/simplify rgbaToHex()() - update completeHexColor(): - add 4-digit hex color support - fix: enforce 8-digit result (even if incomplete input) - update/simplify serializers/deserializers for all param types - fix string param serialization to safely handle non-ASCII chars (using UTF-8 representation) - add/update docstrings
* upstream/master: build build fix: only push params if definitions defined in code build added minter address to the panel update build receive snippet version; allow user defined max length on string param only warn type any
There's one other thing I'd like to get more clarity on (and which might need some additional small adjustments): Default handling. In the |
I'm not sure if this is the right place, since this is more to do with the boilerplate, but it's also very related to this PR and my above comment - so forgive me for adding even more here, but I think the current handling of missing default values for declared fxparams should be re-considered, since it leads to non-deterministic behavior if the Whereas using If the mere presence of params declared via |
@postspectacular looks like this is the new place: https://github.com/fxhash/fxhash-package/tree/main/packages/fxhash-params |
its alright we have seen it and will integrate the improvements soon ™️ |
couldn't push on your branch. changes are incorporated in #22 |
I've been working on simplifying & updating the various fxparam (de)serializers, originally driven by the desire to keep the new boilerplate as lightweight as possible (there's a related PR forthcoming in that repo too). However, then I also spotted a few other things here, which I think this PR improves on:
Numbers / bigints
Simplified both types via better re-use of memory mapped typed arrays and other new, tiny helper functions...
Color
rgbaToHex()
completeHexColor()
:Strings
Strings are now encoded (and decoded) via the native
TextEncoder
API. This uses UTF-8 now and ensures all multi-byte unicode chars are properly and completely encoded (usingString.charCodeAt()
on its own, without further logic does not guarantee that). Please also see further comments in the source (and commit messages)...Select
Ensure serialized value is clamped to 0-255 (even if given invalid input). Update use of default value
Summary
As mentioned, I've also applied the same changes to the Snippet API in the fxhash-boilerplate repo. Will open a related PR for that in a bit (have to still merge the recent changes re: string maxLength)...
Hth! 👍