Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 7663415

Browse files
author
Dimitar Kerezov
committed
Execute only the first replacement method
1 parent 27f57cc commit 7663415

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

helpers.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,16 @@ export function decorateMethod(before: (method1: any, self1: any, args1: any[])
293293
let hasBeenReplaced = false;
294294
let result: any;
295295
if (newMethods && newMethods.length) {
296-
// Find all functions
297-
_(newMethods)
298-
.filter(f => _.isFunction(f))
299-
.each(f => {
300-
// maybe add logger.trace here
301-
hasBeenReplaced = true;
302-
result = f(args, sink.bind(this));
303-
});
296+
const replacementMethods = _.filter(newMethods, f => _.isFunction(f));
297+
if (replacementMethods.length > 0) {
298+
if (replacementMethods.length > 1) {
299+
const $logger = $injector.resolve<ILogger>("logger");
300+
$logger.warn(`Multiple methods detected which try to replace ${sink.name}. Will execute only the first of them.`)
301+
}
302+
303+
hasBeenReplaced = true;
304+
result = _.head(replacementMethods)(args, sink.bind(this));
305+
}
304306
}
305307

306308
if (!hasBeenReplaced) {

0 commit comments

Comments
 (0)