| 1 |
import { AnimationFrameAction } from './AnimationFrameAction'; |
| 2 |
import { AnimationFrameScheduler } from './AnimationFrameScheduler'; |
| 3 |
|
| 4 |
/** |
| 5 |
* |
| 6 |
* Animation Frame Scheduler |
| 7 |
* |
| 8 |
* <span class="informal">Perform task when `window.requestAnimationFrame` would fire</span> |
| 9 |
* |
| 10 |
* When `animationFrame` scheduler is used with delay, it will fall back to {@link asyncScheduler} scheduler |
| 11 |
* behaviour. |
| 12 |
* |
| 13 |
* Without delay, `animationFrame` scheduler can be used to create smooth browser animations. |
| 14 |
* It makes sure scheduled task will happen just before next browser content repaint, |
| 15 |
* thus performing animations as efficiently as possible. |
| 16 |
* |
| 17 |
* ## Example |
| 18 |
* Schedule div height animation |
| 19 |
* ```ts |
| 20 |
* // html: <div style="background: #0ff;"></div> |
| 21 |
* import { animationFrameScheduler } from 'rxjs'; |
| 22 |
* |
| 23 |
* const div = document.querySelector('div'); |
| 24 |
* |
| 25 |
* animationFrameScheduler.schedule(function(height) { |
| 26 |
* div.style.height = height + "px"; |
| 27 |
* |
| 28 |
* this.schedule(height + 1); // `this` references currently executing Action, |
| 29 |
* // which we reschedule with new state |
| 30 |
* }, 0, 0); |
| 31 |
* |
| 32 |
* // You will see a div element growing in height |
| 33 |
* ``` |
| 34 |
*/ |
| 35 |
|
| 36 |
export const animationFrameScheduler = new AnimationFrameScheduler(AnimationFrameAction); |
| 37 |
|
| 38 |
/** |
| 39 |
* @deprecated Renamed to {@link animationFrameScheduler}. Will be removed in v8. |
| 40 |
*/ |
| 41 |
export const animationFrame = animationFrameScheduler; |