You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it is almost time we think about supporting extended serializers (like a preset addon for supporting HTML serialization), even though bundle addition is few bytes still is not needed for many (I imagine most of) users.
Depending on how many hooks we use this would add some overhead because it checks for possible presets and their handlers before each serialization.
interfaceSerializerPreset{/** * Runs before the default serialization. * * @param input - input value to serialize * @param serialize - to use for inner structures * @param context - to serialization context * @returns The serialized string or undefined if not handled */serializeBefore?: (input: unknown,serializer: {serialize: (input: unknown)=>string;context: Map<object,string>;},)=>string|undefined;/** * Runs after the default serialization before the `object.entries` check in `serailizeBuiltInType()` * * @param input- input value to serialize * @param type - type of the input object (for example: "HTMLCollection") * @param serialize - to use for inner structures * @param context - to serialization context * @returns The serialized string or undefined if not handled */serializeAfter?: (input: object,type: string,serializer: {serialize: (input: unknown)=>string;context: Map<object,string>;},)=>string|undefined;}import{serialize}from"ohash";importcustomPresetfrom"ohash/presets/custom";serialize("hello world",{presets: [customPreset]});
[B] Create customized Serializer prototypes using the presets
This would be a bit faster as prototype creation could be optimized to add hooks only when handlers for that specific hook are provided from the presets.
The extend() helper would allow extending the protoype with custom type handlers directly.
This would eliminate the necessity to use hooks at all in some presets.
Creating a custom prototype on each serialize() call would be much slower, so createSerializer() creates the custom Serializer prototype and provides a serialize function to use it with.
Additional information
Would you be willing to help implement this feature?
The text was updated successfully, but these errors were encountered:
Describe the feature
Originally posted by @pi0 in #155 (comment)
I thought about two ways to approach this:
[A] Handle presets within the
Serializer
instanceDepending on how many hooks we use this would add some overhead because it checks for possible presets and their handlers before each serialization.
[B] Create customized
Serializer
prototypes using the presetsThis would be a bit faster as prototype creation could be optimized to add hooks only when handlers for that specific hook are provided from the presets.
The
extend()
helper would allow extending the protoype with custom type handlers directly.This would eliminate the necessity to use hooks at all in some presets.
Creating a custom prototype on each
serialize()
call would be much slower, socreateSerializer()
creates the customSerializer
prototype and provides aserialize
function to use it with.Additional information
The text was updated successfully, but these errors were encountered: