(style, previousScrollTop)
| 326 | * @returns {?*} |
| 327 | */ |
| 328 | const loop = function(style, previousScrollTop) { |
| 329 | |
| 330 | // Continue loop |
| 331 | const repeat = () => { |
| 332 | |
| 333 | // It depends on the browser, but it turns out that closures |
| 334 | // are sometimes faster than .bind or .apply. |
| 335 | requestAnimationFrame(() => loop(style, previousScrollTop)) |
| 336 | |
| 337 | } |
| 338 | |
| 339 | // Get all active instances |
| 340 | const activeInstances = getActiveInstances(instances) |
| 341 | |
| 342 | // Only continue when active instances available |
| 343 | if (activeInstances.length === 0) return repeat() |
| 344 | |
| 345 | const scrollTop = getScrollTop() |
| 346 | |
| 347 | // Only continue when scrollTop has changed |
| 348 | if (previousScrollTop === scrollTop) return repeat() |
| 349 | else previousScrollTop = scrollTop |
| 350 | |
| 351 | // Get and set new props of each instance |
| 352 | activeInstances |
| 353 | .map((instance) => getProps(instance, scrollTop)) |
| 354 | .forEach(({ elem, props }) => setProps(elem, props)) |
| 355 | |
| 356 | repeat() |
| 357 | |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Creates a new instance. |
no test coverage detected