move live recording logic down the component tree
This commit is contained in:
parent
56467485f5
commit
21caa6df12
4 changed files with 115 additions and 13 deletions
|
@ -22,7 +22,7 @@ limitations under the License.
|
|||
* The function starts unmarked.
|
||||
*/
|
||||
export class MarkedExecution {
|
||||
private marked = false;
|
||||
private _marked = false;
|
||||
|
||||
/**
|
||||
* Creates a MarkedExecution for the provided function.
|
||||
|
@ -33,26 +33,33 @@ export class MarkedExecution {
|
|||
constructor(private fn: () => void, private onMarkCallback?: () => void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the _marked property
|
||||
*/
|
||||
public get marked() {
|
||||
return this._marked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the mark without calling the function.
|
||||
*/
|
||||
public reset() {
|
||||
this.marked = false;
|
||||
this._marked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the function to be called upon trigger().
|
||||
*/
|
||||
public mark() {
|
||||
if (!this.marked) this.onMarkCallback?.();
|
||||
this.marked = true;
|
||||
if (!this._marked) this.onMarkCallback?.();
|
||||
this._marked = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If marked, the function will be called, otherwise this does nothing.
|
||||
*/
|
||||
public trigger() {
|
||||
if (!this.marked) return;
|
||||
if (!this._marked) return;
|
||||
this.reset(); // reset first just in case the fn() causes a trigger()
|
||||
this.fn();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue