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

Method calcTaskScore_

src/service/resources-impl.js:1399–1412  ·  view source on GitHub ↗

* Calculates the task's score. A task with the lowest score will be dequeued * from the queue the first. * * There are three components of the score: element's priority, operation or * offset priority and viewport priority. * * Element's priority is constant of the element's name.

(task)

Source from the content-addressed store, hash-verified

1397 * @private
1398 */
1399 calcTaskScore_(task) {
1400 // TODO(jridgewell): these should be taking into account the active
1401 // scroller, which may not be the root scroller. Maybe a weighted average
1402 // of "scroller scrolls necessary" to see the element.
1403 // Demo at https://output.jsbin.com/hicigom/quiet
1404 const viewport = this.viewport_.getRect();
1405 const box = task.resource.getLayoutBox();
1406 let posPriority = Math.floor((box.top - viewport.top) / viewport.height);
1407 if (Math.sign(posPriority) != this.getScrollDirection()) {
1408 posPriority *= 2;
1409 }
1410 posPriority = Math.abs(posPriority);
1411 return task.priority * PRIORITY_BASE_ + posPriority;
1412 }
1413
1414 /**
1415 * Calculates the timeout of a task. The timeout depends on two main factors:

Callers 1

test-resources.jsFile · 0.80

Calls 4

getScrollDirectionMethod · 0.95
signMethod · 0.80
getRectMethod · 0.45
getLayoutBoxMethod · 0.45

Tested by

no test coverage detected