wishthis/node_modules/rxjs/dist/esm/internal/observable/dom/animationFrames.js

29 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-06-08 10:36:39 +00:00
import { Observable } from '../../Observable';
import { Subscription } from '../../Subscription';
import { performanceTimestampProvider } from '../../scheduler/performanceTimestampProvider';
import { animationFrameProvider } from '../../scheduler/animationFrameProvider';
export function animationFrames(timestampProvider) {
return timestampProvider ? animationFramesFactory(timestampProvider) : DEFAULT_ANIMATION_FRAMES;
}
function animationFramesFactory(timestampProvider) {
const { schedule } = animationFrameProvider;
return new Observable((subscriber) => {
const subscription = new Subscription();
const provider = timestampProvider || performanceTimestampProvider;
const start = provider.now();
const run = (timestamp) => {
const now = provider.now();
subscriber.next({
timestamp: timestampProvider ? now : timestamp,
elapsed: now - start,
});
if (!subscriber.closed) {
subscription.add(schedule(run));
}
};
subscription.add(schedule(run));
return subscription;
});
}
const DEFAULT_ANIMATION_FRAMES = animationFramesFactory();
//# sourceMappingURL=animationFrames.js.map