@@ -94,7 +94,7 @@ export function AnimateJsProvider($animateProvider) {
9494 }
9595
9696 // no matching animations
97- if ( ! before && ! after ) return ;
97+ if ( ! before && ! after ) return undefined ;
9898
9999 function applyOptions ( ) {
100100 options . domOperation ( ) ;
@@ -231,32 +231,38 @@ export function AnimateJsProvider($animateProvider) {
231231 } ,
232232 } ;
233233
234- function executeAnimationFn ( fn , element , event , options , onDone ) {
234+ function executeAnimationFn (
235+ fn ,
236+ elemParam ,
237+ eventParam ,
238+ optionsParam ,
239+ onDone ,
240+ ) {
235241 let args ;
236242
237- switch ( event ) {
243+ switch ( eventParam ) {
238244 case "animate" :
239- args = [ element , options . from , options . to , onDone ] ;
245+ args = [ elemParam , optionsParam . from , optionsParam . to , onDone ] ;
240246 break ;
241247
242248 case "setClass" :
243- args = [ element , classesToAdd , classesToRemove , onDone ] ;
249+ args = [ elemParam , classesToAdd , classesToRemove , onDone ] ;
244250 break ;
245251
246252 case "addClass" :
247- args = [ element , classesToAdd , onDone ] ;
253+ args = [ elemParam , classesToAdd , onDone ] ;
248254 break ;
249255
250256 case "removeClass" :
251- args = [ element , classesToRemove , onDone ] ;
257+ args = [ elemParam , classesToRemove , onDone ] ;
252258 break ;
253259
254260 default :
255- args = [ element , onDone ] ;
261+ args = [ elemParam , onDone ] ;
256262 break ;
257263 }
258264
259- args . push ( options ) ;
265+ args . push ( optionsParam ) ;
260266
261267 let value = fn . apply ( fn , args ) ;
262268
@@ -279,41 +285,22 @@ export function AnimateJsProvider($animateProvider) {
279285 }
280286
281287 function groupEventedAnimations (
282- element ,
283- event ,
284- options ,
285- animations ,
288+ elemParam ,
289+ eventParam ,
290+ optionsParam ,
291+ animationsParam ,
286292 fnName ,
287293 ) {
288294 const operations = [ ] ;
289295
290- animations . forEach ( ( ani ) => {
296+ animationsParam . forEach ( ( ani ) => {
291297 const animation = ani [ fnName ] ;
292298
293299 if ( ! animation ) return ;
294300
295301 // note that all of these animations will run in parallel
296302 operations . push ( ( ) => {
297- let runner ;
298-
299- let endProgressCb ;
300-
301- let resolved = false ;
302-
303- const onAnimationComplete = function ( rejected ) {
304- if ( ! resolved ) {
305- resolved = true ;
306- (
307- endProgressCb ||
308- ( ( ) => {
309- /* empty */
310- } )
311- ) ( rejected ) ;
312- runner . complete ( ! rejected ) ;
313- }
314- } ;
315-
316- runner = new AnimateRunner ( {
303+ const newRunner = new AnimateRunner ( {
317304 end ( ) {
318305 onAnimationComplete ( ) ;
319306 } ,
@@ -322,37 +309,52 @@ export function AnimateJsProvider($animateProvider) {
322309 } ,
323310 } ) ;
324311
325- endProgressCb = executeAnimationFn (
312+ const endProgressCb = executeAnimationFn (
326313 animation ,
327- element ,
328- event ,
329- options ,
314+ elemParam ,
315+ eventParam ,
316+ optionsParam ,
330317 ( result ) => {
331318 const cancelled = result === false ;
332319
333320 onAnimationComplete ( cancelled ) ;
334321 } ,
335322 ) ;
336323
337- return runner ;
324+ let resolved = false ;
325+
326+ const onAnimationComplete = function ( rejected ) {
327+ if ( ! resolved ) {
328+ resolved = true ;
329+ (
330+ endProgressCb ||
331+ ( ( ) => {
332+ /* empty */
333+ } )
334+ ) ( rejected ) ;
335+ newRunner . complete ( ! rejected ) ;
336+ }
337+ } ;
338+
339+ return newRunner ;
338340 } ) ;
339341 } ) ;
340342
341343 return operations ;
342344 }
343345
344346 function packageAnimations (
345- element ,
346- event ,
347- options ,
348- animations ,
347+ elementParam ,
348+ eventParam ,
349+ optionsParam ,
350+ animationsParam ,
349351 fnName ,
350352 ) {
351353 let operations = groupEventedAnimations (
352- element ,
353- event ,
354- options ,
355- animations ,
354+ elementParam ,
355+ eventParam ,
356+ optionsParam ,
357+ animationsParam ,
356358 fnName ,
357359 ) ;
358360
@@ -363,32 +365,32 @@ export function AnimateJsProvider($animateProvider) {
363365
364366 if ( fnName === "beforeSetClass" ) {
365367 a = groupEventedAnimations (
366- element ,
368+ elementParam ,
367369 "removeClass" ,
368- options ,
369- animations ,
370+ optionsParam ,
371+ animationsParam ,
370372 "beforeRemoveClass" ,
371373 ) ;
372374 b = groupEventedAnimations (
373- element ,
375+ elementParam ,
374376 "addClass" ,
375- options ,
376- animations ,
377+ optionsParam ,
378+ animationsParam ,
377379 "beforeAddClass" ,
378380 ) ;
379381 } else if ( fnName === "setClass" ) {
380382 a = groupEventedAnimations (
381- element ,
383+ elementParam ,
382384 "removeClass" ,
383- options ,
384- animations ,
385+ optionsParam ,
386+ animationsParam ,
385387 "removeClass" ,
386388 ) ;
387389 b = groupEventedAnimations (
388- element ,
390+ elementParam ,
389391 "addClass" ,
390- options ,
391- animations ,
392+ optionsParam ,
393+ animationsParam ,
392394 "addClass" ,
393395 ) ;
394396 }
0 commit comments