-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(component): use RenderScheduler as a service
- Loading branch information
1 parent
d0e544b
commit 5aa2354
Showing
5 changed files
with
64 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
import { ChangeDetectorRef } from '@angular/core'; | ||
import { ChangeDetectorRef, inject, Injectable } from '@angular/core'; | ||
import { TickScheduler } from './tick-scheduler'; | ||
|
||
export interface RenderScheduler { | ||
schedule(): void; | ||
} | ||
|
||
export interface RenderSchedulerConfig { | ||
cdRef: ChangeDetectorRef; | ||
tickScheduler: TickScheduler; | ||
} | ||
@Injectable() | ||
export class RenderScheduler { | ||
constructor( | ||
private cdRef: ChangeDetectorRef, | ||
private tickScheduler: TickScheduler | ||
) {} | ||
|
||
export function createRenderScheduler( | ||
config: RenderSchedulerConfig | ||
): RenderScheduler { | ||
function schedule(): void { | ||
config.cdRef.markForCheck(); | ||
config.tickScheduler.schedule(); | ||
schedule(): void { | ||
this.cdRef.markForCheck(); | ||
this.tickScheduler.schedule(); | ||
} | ||
} | ||
|
||
return { schedule }; | ||
export function createRenderScheduler(): RenderScheduler { | ||
return new RenderScheduler(inject(ChangeDetectorRef), inject(TickScheduler)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters