Skip to content

Commit

Permalink
chore: Use WeakMap to store JsonMapper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed May 16, 2021
1 parent 8ab709f commit cc5bd27
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions packages/json-mapper/src/domain/JsonMapperTypesContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ import {JsonMapperMethods} from "../interfaces/JsonMapperMethods";
* @ignore
*/
// tslint:disable-next-line:variable-name
const JsonMapperTypesContainer: Map<Type<any> | Symbol, {token: Type<JsonMapperMethods>; instance: JsonMapperMethods}> = new Map();
const JsonMapperTypesContainer: Map<Type<any> | Symbol, JsonMapperMethods> = new Map();
/**
* @ignore
*/
export function registerJsonTypeMapper(type: Type<any>, token: Type<JsonMapperMethods>) {
JsonMapperTypesContainer.set(type, {token, instance: new token()});
JsonMapperTypesContainer.set(type, new token());
}
/**
* @ignore
*/
export function getJsonMapperTypes(): Map<Type<any> | Symbol, JsonMapperMethods> {
return new Map(
Array.from(JsonMapperTypesContainer.entries()).map(([key, {instance}]) => {
return [key, instance];
})
);
export function getJsonMapperTypes(): WeakMap<Type<any> | Symbol, JsonMapperMethods> {
return JsonMapperTypesContainer;
}
2 changes: 1 addition & 1 deletion packages/json-mapper/src/utils/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface JsonDeserializerOptions<T = any, C = any> extends MetadataTypes
/**
* Types used to map complex types (Symbol, Array, Set, Map)
*/
types?: Map<Type<any>, JsonMapperMethods>;
types?: WeakMap<Type<any>, JsonMapperMethods>;
/**
* useAlias mapping
*/
Expand Down

0 comments on commit cc5bd27

Please sign in to comment.