### File

`src/utils/animation-frame.service.ts`

### Index

###### Properties
Protected animationFrameId Protected frameSource Public tick
###### Methods
Protected doTick ngOnDestroy

### Constructor

`constructor(ngZone: NgZone)`
Defined in src/utils/animation-frame.service.ts:10
Parameters :
Name | Type | Optional
ngZone | `NgZone` | No

### Methods

Protected doTick
`doTick(frame: number)`
Defined in src/utils/animation-frame.service.ts:23
Parameters :
Name | Type | Optional
frame | `number` | No
Returns : `void`

ngOnDestroy
`ngOnDestroy()`
Defined in src/utils/animation-frame.service.ts:19
Returns : `void`

### Properties

Protected animationFrameId
`animationFrameId: `number``
Type : `number`
Defined in src/utils/animation-frame.service.ts:10

Protected frameSource
`frameSource: ```
Default value : `new Subject<number>()`
Defined in src/utils/animation-frame.service.ts:8

Public tick
`tick: `Observable<number>``
Type : `Observable<number>`
Defined in src/utils/animation-frame.service.ts:6

    import { Injectable, OnDestroy, NgZone } from "@angular/core";
    import { Observable, Subject, from } from "rxjs";

    @Injectable()
    export class AnimationFrameServiceSingleton implements OnDestroy {
    	public tick: Observable<number>;

    	protected frameSource = new Subject<number>();

    	protected animationFrameId: number;

    	constructor(protected ngZone: NgZone) {
    		this.tick = this.frameSource.asObservable();
    		this.ngZone.runOutsideAngular(() => {
    			this.animationFrameId = requestAnimationFrame(this.doTick.bind(this));
    		});
    	}

    	ngOnDestroy() {
    		cancelAnimationFrame(this.animationFrameId);
    	}

    	protected doTick(frame: number) {
    		this.frameSource.next(frame);
    		this.ngZone.runOutsideAngular(() => {
    			requestAnimationFrame(this.doTick.bind(this));
    		});
    	}
    }

    @Injectable()
    export class AnimationFrameService {
    	public tick: Observable<number>;

    	constructor(protected singleton: AnimationFrameServiceSingleton) {
    		this.tick = from(this.singleton.tick);
    	}
    }

# result-matching ""

# No results matching ""