Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Registry

The registry allows the serializer to handle inheritance.

Example with the default registry:

// Create a new Serializer with the default registry.
const serializer = new Serializer();

// Then add registrations to the inner registry.
serializer.registry.add([
     {
         parent: Foo,
         children: {
             bar: Bar,
             baz: Baz,
         }
     }
]);

Example with a specific registry:

// Create the registry.
const registry = new Registry();
registry.add([
     {
         parent: Foo,
         children: {
             bar: Bar,
             baz: Baz,
         }
     }
]);

// Then create a Serializer with a specific registry.
const serializer = new Serializer(registry);

// It is always possible to register new classes after, or to add entries to already known classes.
registry.add([
     {
         parent: Foo,
         children: {
             bar: NewBar,
         }
     }
]);

Hierarchy

  • Registry

Index

Methods

Methods

add

findClass

  • findClass<T, V>(clazz: Class<T>, obj: any): Instantiable<V>
  • Use the class Parent metadata in combination with the registrations to find the correct class for the given object.

    Type parameters

    • T

    • V: T

    Parameters

    • clazz: Class<T>
    • obj: any

    Returns Instantiable<V>

    the class of the given object.

Generated using TypeDoc