Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Constructors

Methods

  • addSerializer(name: string, serializer: SerializerBase<Object, Object, (new () => Object) | (new (...args: any[]) => Object)>): boolean
  • Add a custom serializer

    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

    return if the serializer is correctly added

  • stringify(obj: unknown): string
  • Stringify object

    Parameters

    • obj: unknown

      The data to stringify

    Returns string

    JSON string of the object

  • parse(jsonString: string): unknown
  • Parse object

    Parameters

    • jsonString: string

      Json string to parse

    Returns unknown

    The value of the jsonString

  • _serializerStringify(obj: unknown, fallback?: boolean): unknown
  • Call all custom serializer

    Parameters

    • obj: unknown

      Object to serialize

    • fallback: boolean = false

    Returns unknown

    The value after the custom serializer or fallback

  • _serializerParse(obj: unknown): unknown
  • Call all custom serializer

    Parameters

    • obj: unknown

      The current parse value

    Returns unknown

    The value after the custom parse or the input obj

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