Skip to content

Commit 2e74ed9

Browse files
committed
Fixed predicate run outside ngZone
1 parent 122d340 commit 2e74ed9

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {NgZone} from '@angular/core';
1+
import {ɵmarkDirty as markDirty} from '@angular/core';
22
import {Predicate} from '../types/predicate';
33

44
/**
55
* TODO: This will not be needed in Angular 10
66
* when libraries are allowed to use Ivy renderer and markDirty becomes stable API
77
*/
8-
export function shouldCall<T>(predicate: Predicate<T>): MethodDecorator {
8+
/* export function shouldCall<T>(predicate: Predicate<T>): MethodDecorator {
99
return (_, key, desc: PropertyDescriptor) => {
1010
const {value} = desc;
1111
@@ -23,20 +23,20 @@ export function shouldCall<T>(predicate: Predicate<T>): MethodDecorator {
2323
});
2424
};
2525
};
26-
}
26+
} */
2727

2828
/**
2929
* TODO: Use this in Angular 10
3030
*/
31-
// export function shouldCall<T extends object>(predicate: Predicate<T>): MethodDecorator {
32-
// return (_: Object, _key: string | symbol, desc: PropertyDescriptor) => {
33-
// const {value} = desc;
34-
//
35-
// desc.value = function(this: T, ...args: any[]) {
36-
// if (predicate.apply(this, args)) {
37-
// value.apply(this, args);
38-
// markDirty(this);
39-
// }
40-
// };
41-
// };
42-
// }
31+
export function shouldCall<T extends object>(predicate: Predicate<T>): MethodDecorator {
32+
return (_: Object, _key: string | symbol, desc: PropertyDescriptor) => {
33+
const {value} = desc;
34+
35+
desc.value = function (this: T, ...args: any[]) {
36+
if (predicate.apply(this, args)) {
37+
value.apply(this, args);
38+
markDirty(this);
39+
}
40+
};
41+
};
42+
}

0 commit comments

Comments
 (0)