Skip to content

Commit a562acd

Browse files
committed
[web-animations-1] Tweak examples to not use forEach()
1 parent 1513daa commit a562acd

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

web-animations-1/Overview.bs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ const isAnimating = elem.getAnimations().some(
284284
<div class='example'>
285285
<pre class='lang-javascript'>
286286
// Pause all existing animations in the document
287-
document.getAnimations().forEach(
288-
animation =&gt; animation.pause()
289-
);
287+
for (const animation of document.getAnimations()) {
288+
animation.pause()
289+
}
290290
</pre>
291291
</div>
292292

@@ -318,13 +318,16 @@ elem.animate({ transform: 'scale(0)', opacity: 0 }, 300);
318318
<div class='example'>
319319
<pre class='lang-javascript'>
320320
// Print the id of any opacity animations on elem
321-
elem.getAnimations().filter(
322-
animation =&gt;
321+
for (const animation of elem.getAnimations()) {
322+
if (
323323
animation.effect instanceof KeyframeEffect &&
324-
animation.effect.getKeyframes().some(
325-
frame =&gt; frame.hasOwnProperty('opacity')
326-
)
327-
).forEach(animation =&gt; console.log(animation.id));
324+
animation.effect
325+
.getKeyframes()
326+
.some(frame =&gt; frame.hasOwnProperty('opacity'))
327+
) {
328+
console.log(animation.id);
329+
}
330+
}
328331
</pre>
329332
</div>
330333

@@ -334,16 +337,18 @@ elem.getAnimations().filter(
334337
<div class='example'>
335338
<pre class='lang-javascript'>
336339
// Slow down and replay any transform animations
337-
elem.getAnimations().filter(
340+
const transformAnimations = elem.getAnimations().filter(
338341
animation =&gt;
339342
animation.effect instanceof KeyframeEffect &&
340343
animation.effect.getKeyframes().some(
341344
frame =&gt; frame.hasOwnProperty('transform')
342345
)
343-
).forEach(animation =&gt; {
346+
);
347+
348+
for (const animation of transformAnimations) {
344349
animation.currentTime = 0;
345350
animation.updatePlaybackRate(0.5);
346-
});
351+
}
347352
</pre>
348353
</div>
349354

@@ -355,18 +360,16 @@ elem.getAnimations().filter(
355360
<div class='example'>
356361
<pre class='lang-javascript'>
357362
// Seek to the half-way point of an animation and check that the opacity is 50%
358-
elem.getAnimations().forEach(
359-
animation =&gt;
360-
animation.currentTime =
361-
animation.effect.getComputedTiming().delay +
362-
animation.effect.getComputedTiming().activeDuration / 2;
363-
);
363+
for (const animation of elem.getAnimations()) {
364+
const { delay, activeDuration } = animation.effect.getComputedTiming();
365+
animation.currentTime = delay + activeDuration / 2;
366+
}
364367
assert.strictEqual(getComputedStyle(elem).opacity, '0.5');
365368

366369
// Check that the loading screen is hidden after the animations finish
367-
elem.getAnimations().forEach(
368-
animation =&gt; animation.finish()
369-
);
370+
for (const animation of elem.getAnimations()) {
371+
animation.finish();
372+
}
370373
// Wait one frame so that event handlers have a chance to run
371374
requestAnimationFrame(() =&gt; {
372375
assert.strictEqual(

0 commit comments

Comments
 (0)