Class DataSerializer

A class that handles the stringification and parsing of the data that will be sent through PostMessage. This has two main differences with JSON.parse/JSON.stringify.

  • It allows loading custom domain serializer that could be loaded dynamically
  • It excludes from serialization all the property of objects which start with an "_" (underscore) This allows having more than javascript primitive to be serialized and also to keep some property to be transferred because they shouldn't or they technically can't be transferred. For example, a security token might not be transferred or an HTMLElement reference couldn't be technically transferred. In that case, it could still be interesting to use it in a store but you never want them to be transferred.

Hierarchy

  • DataSerializer

Constructors

Methods

  • Add a custom serializer

    Returns

    return if the serializer is correctly added

    Parameters

    • name: string

      The name of the serializer

    • serializer: SerializerBase<Object, Object, (new () => Object) | (new (...args: any[]) => Object)>

      A serializer which extends and implement SerializerBase

    Returns boolean

  • Stringify object

    Returns

    JSON string of the object

    Parameters

    • obj: unknown

      The data to stringify

    Returns string

  • Parse object

    Returns

    The value of the jsonString

    Parameters

    • jsonString: string

      Json string to parse

    Returns unknown

  • Call all custom serializer

    Returns

    The value after the custom serializer or fallback

    Parameters

    • obj: unknown

      Object to serialize

    • Optional fallback: boolean = false

      Default value if we can't find a dataSerializer for it

    Returns unknown

  • Call all custom serializer

    Returns

    The value after the custom parse or the input obj

    Parameters

    • obj: unknown

      The current parse value

    Returns unknown

Properties

_serializers: Map<string, SerializerBase<Object, Object, (new () => Object) | (new (...args: any[]) => Object)>> = ...

Internal array to save all custom serializer we have register

Generated using TypeDoc