import {SerializerContainer} from 'ug-layout/serialization/SerializerContainer'
SerializerContainer
A container for running and determining serializers.
Example:
const container = new SerializerContainer();
class MyClass {}
const mySerializer = new GenericSerializer('MyClass', MyClass);
container.registerSerializer(MyClass, mySerializer);
container.serialize(new MyClass()); // => { name: 'MyClass' }
container.deserialize({ name: 'MyClass' }); // => MyClass
Constructor Summary
Public Constructor | ||
public |
constructor(config: SerializerContainerConfig) Creates an instance of SerializerContainer. |
Method Summary
Public Methods | ||
public |
deserialize(serialized: S): R Deserializes a serialized node using the registered serializer for that node type. |
|
public |
deserializeList(serialized: *): * |
|
public |
isExcluded(instance: *): boolean |
|
public |
registerClass(name: string, _Class: Type<any>) Registers a class that can be identified by a string representation. |
|
public |
registerClasses(classes: {[key: string]}) Registers multiple classes that can be identified by a string representation. |
|
public |
registerSerializer(_Class: Type<any>, serializer: BaseSerializer | Type<BaseSerializer>, options: {skipRegister?: boolean}) Registers a serializer with the container. |
|
public |
Resolves a token with this containers injector. |
|
public |
resolveClass(name: string): Type<any> | null Resolves a string to a registered class. |
|
public |
resolveClassString(_Class: Type<any>): string | null Resolves a class to it's registered string representation. |
|
public |
resolveFromClass(_Class: Type<any>): BaseSerializer | null Resolves a serializer from a class. |
|
public |
resolveFromInstance(instance: Renderable & Constructable<any>): BaseSerializer | null Resolves a serializer from an instance of a registered class. |
|
public |
resolveFromSerialized(node: Serialized): BaseSerializer | null Resolves a serializer from a serialized node. |
|
public |
serialize(instance: R): S Serializes a class instance using the registered serializer for that class. |
|
public |
serializeList(instances: *): * |
Public Constructors
public constructor(config: SerializerContainerConfig) source
Creates an instance of SerializerContainer.
Params:
Name | Type | Attribute | Description |
config | SerializerContainerConfig |
|
Public Methods
public deserialize(serialized: S): R source
Deserializes a serialized node using the registered serializer for that node type.
Params:
Name | Type | Attribute | Description |
serialized | S |
Return:
R | The renderable argument. |
public deserializeList(serialized: *): * source
Params:
Name | Type | Attribute | Description |
serialized | * |
Return:
* |
public registerClass(name: string, _Class: Type<any>) source
Registers a class that can be identified by a string representation.
public registerClasses(classes: {[key: string]}) source
Registers multiple classes that can be identified by a string representation.
Params:
Name | Type | Attribute | Description |
classes | {[key: string]} |
|
public registerSerializer(_Class: Type<any>, serializer: BaseSerializer | Type<BaseSerializer>, options: {skipRegister?: boolean}) source
Registers a serializer with the container.
public resolve(token: *): T | null source
Resolves a token with this containers injector.
Params:
Name | Type | Attribute | Description |
token | * |
public resolveClass(name: string): Type<any> | null source
Resolves a string to a registered class.
Params:
Name | Type | Attribute | Description |
name | string |
public resolveClassString(_Class: Type<any>): string | null source
Resolves a class to it's registered string representation.
Params:
Name | Type | Attribute | Description |
_Class | Type<any> |
public resolveFromClass(_Class: Type<any>): BaseSerializer | null source
Resolves a serializer from a class.
Params:
Name | Type | Attribute | Description |
_Class | Type<any> |
public resolveFromInstance(instance: Renderable & Constructable<any>): BaseSerializer | null source
Resolves a serializer from an instance of a registered class.
Params:
Name | Type | Attribute | Description |
instance | Renderable & Constructable<any> |
public resolveFromSerialized(node: Serialized): BaseSerializer | null source
Resolves a serializer from a serialized node.
Params:
Name | Type | Attribute | Description |
node | Serialized |
public serialize(instance: R): S source
Serializes a class instance using the registered serializer for that class.
Params:
Name | Type | Attribute | Description |
instance | R |
Return:
S | The serialized node. |
public serializeList(instances: *): * source
Params:
Name | Type | Attribute | Description |
instances | * |
Return:
* |