MCPcopy
hub / github.com/animatedjs/animated / parallel

Function parallel

src/index.js:200–248  ·  view source on GitHub ↗
(
  animations: Array<CompositeAnimation>,
  config?: ?ParallelConfig,
)

Source from the content-addressed store, hash-verified

198 stopTogether?: bool; // If one is stopped, stop all. default: true
199}
200var parallel = function(
201 animations: Array<CompositeAnimation>,
202 config?: ?ParallelConfig,
203): CompositeAnimation {
204 var doneCount = 0;
205 // Make sure we only call stop() at most once for each animation
206 var hasEnded = {};
207 var stopTogether = !(config && config.stopTogether === false);
208
209 var result = {
210 start: function(callback?: ?EndCallback) {
211 if (doneCount === animations.length) {
212 callback && callback({finished: true});
213 return;
214 }
215
216 animations.forEach((animation, idx) => {
217 var cb = function(endResult) {
218 hasEnded[idx] = true;
219 doneCount++;
220 if (doneCount === animations.length) {
221 doneCount = 0;
222 callback && callback(endResult);
223 return;
224 }
225
226 if (!endResult.finished && stopTogether) {
227 result.stop();
228 }
229 };
230
231 if (!animation) {
232 cb({finished: true});
233 } else {
234 animation.start(cb);
235 }
236 });
237 },
238
239 stop: function(): void {
240 animations.forEach((animation, idx) => {
241 !hasEnded[idx] && animation.stop();
242 hasEnded[idx] = true;
243 });
244 }
245 };
246
247 return result;
248};
249
250var delay = function(time: number): CompositeAnimation {
251 // Would be nice to make a specialized implementation

Callers 2

maybeVectorAnimFunction · 0.85
staggerFunction · 0.85

Calls 3

cbFunction · 0.85
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…