* 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)
| 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_() { |
no test coverage detected