Skip to content

Commit

Permalink
feat(core): use postMap if available
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Mar 6, 2021
1 parent 9552516 commit fb22792
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/lib/create-mapper/create-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function createMapper<TKey = unknown>({
return sourceObj;
}

const { preMap } = plugin;
const { preMap, postMap } = plugin;

// run preMap if available
const [sourceInstance] = preMap
Expand All @@ -79,13 +79,15 @@ export function createMapper<TKey = unknown>({
'extraArguments' in destinationObjOrOptions)) ||
destinationObjOrOptions == null
) {
return mapReturn(
const result = mapReturn(
sourceInstance ?? sourceObj,
mapping!,
destinationObjOrOptions as MapOptions,
this,
errorHandler
);

return postMap ? postMap.bind(plugin)(destination, result) : result;
}

mapMutate(
Expand All @@ -96,6 +98,9 @@ export function createMapper<TKey = unknown>({
errorHandler,
destinationObjOrOptions
);
if (postMap) {
destinationObjOrOptions = postMap(destination, destinationObjOrOptions);
}
},
mapAsync(
sourceObj: Record<string, unknown>,
Expand Down

0 comments on commit fb22792

Please sign in to comment.