Skip to content

Commit

Permalink
feat(classes): expose instantiate
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Mar 6, 2021
1 parent 904e5c8 commit b2dd592
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions packages/classes/src/lib/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export const classes: MapPluginInitializer<Constructible> = (errorHandler) => {
const instanceStorage = new ClassInstanceStorage();

return {
instantiate<TModel extends Dictionary<TModel> = any>(
model: Constructible<TModel>,
obj?: TModel
) {
return instantiate(instanceStorage, metadataStorage, model, obj);
},
initializeMapping(source, destination, options?) {
// If a mapping already exists, handle error and return;
if (mappingStorage.has(source, destination)) {
Expand All @@ -52,15 +58,12 @@ export const classes: MapPluginInitializer<Constructible> = (errorHandler) => {
* ```
* `Foo#bar` is a nested constructible
*/
const [destinationInstance, destinationNestedConstructible] = instantiate(
instanceStorage,
metadataStorage,
destination
);
const [
destinationInstance,
destinationNestedConstructible,
] = this.instantiate(destination);

const [sourceInstance, sourceNestedConstructible] = instantiate(
instanceStorage,
metadataStorage,
const [sourceInstance, sourceNestedConstructible] = this.instantiate(
source
);

Expand Down Expand Up @@ -130,15 +133,8 @@ export const classes: MapPluginInitializer<Constructible> = (errorHandler) => {
destinationObj?: TDestination
) {
// Prepare the sourceInstance/destinationInstance with plain object sourceObj and destinationObj
const [sourceInstance] = instantiate(
instanceStorage,
metadataStorage,
source,
sourceObj
);
const [destinationInstance] = instantiate(
instanceStorage,
metadataStorage,
const [sourceInstance] = this.instantiate(source, sourceObj);
const [destinationInstance] = this.instantiate(
destination,
destinationObj
);
Expand Down

0 comments on commit b2dd592

Please sign in to comment.