MCPcopy
hub / github.com/ampproject/amphtml / runAnimMutateSeries

Method runAnimMutateSeries

src/service/vsync-impl.js:342–365  ·  view source on GitHub ↗

* Runs the series of mutates until the mutator returns a false value. * @param {!Node} contextNode * @param {function(time, time, !VsyncStateDef):boolean} mutator The * mutator callback. Only expected to do DOM writes, not reads. If the * returned value is true, the vsync task will b

(contextNode, mutator, opt_timeout)

Source from the content-addressed store, hash-verified

340 * timeout.
341 */
342 runAnimMutateSeries(contextNode, mutator, opt_timeout) {
343 if (!this.canAnimate_(contextNode)) {
344 return Promise.reject(cancellation());
345 }
346 return new Promise((resolve, reject) => {
347 const startTime = Date.now();
348 let prevTime = 0;
349 const task = this.createAnimTask(contextNode, {
350 mutate: (state) => {
351 const timeSinceStart = Date.now() - startTime;
352 const res = mutator(timeSinceStart, timeSinceStart - prevTime, state);
353 if (!res) {
354 resolve();
355 } else if (opt_timeout && timeSinceStart > opt_timeout) {
356 reject(new Error('timeout'));
357 } else {
358 prevTime = timeSinceStart;
359 task(state);
360 }
361 },
362 });
363 task({});
364 });
365 }
366
367 /** @private */
368 schedule_() {

Callers 2

test-vsync.jsFile · 0.80
runContinuing_Method · 0.80

Calls 5

canAnimate_Method · 0.95
createAnimTaskMethod · 0.95
cancellationFunction · 0.90
nowMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected