Skip to content

Commit 725629a

Browse files
committed
feat: add .reprocessAfter() method
This allows temporarily disabling automatic reprocessing.
1 parent ff200a9 commit 725629a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

source/processors/complex-processor.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface ComplexProcessorApi<TData> extends SubjectApi<TData> {
2121
*/
2222
export abstract class ComplexProcessor<TData> extends Subject<TData> implements ComplexProcessorApi<TData> {
2323
protected _processing: boolean = false;
24+
protected _willReprocessAfter: boolean = false;
2425
protected _active: boolean = true;
2526

2627
public get processing(): boolean {
@@ -80,7 +81,20 @@ export abstract class ComplexProcessor<TData> extends Subject<TData> implements
8081
return this.process(this.lastInput, force);
8182
}
8283

84+
/**
85+
* Disables automatic reprocessing within the provided method.
86+
*/
87+
public reprocessAfter(method: () => void, force?: boolean): TData {
88+
this._willReprocessAfter = true;
89+
90+
method();
91+
92+
this._willReprocessAfter = false;
93+
94+
return this.reprocess(force);
95+
}
96+
8397
protected shouldProcess(force: boolean = false): boolean {
84-
return !this._processing && (this.active || force);
98+
return !this._willReprocessAfter && !this._processing && (this.active || force);
8599
}
86100
}

0 commit comments

Comments
 (0)