@@ -42,27 +42,59 @@ export class CubicBezierAnimationCurve implements definition.CubicBezierAnimatio
4242 }
4343}
4444
45+ // This is a BOGUS Class to make TypeScript happy - This is not needed other than to make TS happy.
46+ // We didn't want to actually modify Promise; as the cancel() is ONLY valid for animations "Promise"
47+ export class AnimationPromise implements definition . AnimationPromise {
48+ public cancel ( ) : void { /* Do Nothing */ }
49+ public then ( onFulfilled ?: ( value ?: any ) => void , onRejected ?: ( error ?: any ) => void ) : AnimationPromise { return new AnimationPromise ( ) ; }
50+ public catch ( onRejected ?: ( error ?: any ) => void ) : AnimationPromise { return new AnimationPromise ( ) ; }
51+ }
52+
4553export class Animation implements definition . Animation {
4654 public _propertyAnimations : Array < PropertyAnimation > ;
4755 public _playSequentially : boolean ;
4856 private _isPlaying : boolean ;
4957 private _resolve ;
5058 private _reject ;
5159
52- public play ( ) : Promise < void > {
60+ public play ( ) : AnimationPromise {
5361 if ( this . isPlaying ) {
5462 throw new Error ( "Animation is already playing." ) ;
5563 }
5664
57- var animationFinishedPromise = new Promise < void > ( ( resolve , reject ) => {
65+ // We have to actually create a "Promise" due to a bug in the v8 engine and decedent promises
66+ // We just cast it to a animationPromise so that all the rest of the code works fine
67+ var animationFinishedPromise = < AnimationPromise > new Promise < void > ( ( resolve , reject ) => {
5868 this . _resolve = resolve ;
5969 this . _reject = reject ;
6070 } ) ;
6171
72+ this . fixupAnimationPromise ( animationFinishedPromise ) ;
73+
6274 this . _isPlaying = true ;
6375 return animationFinishedPromise ;
6476 }
6577
78+ private fixupAnimationPromise ( promise : AnimationPromise ) : void {
79+ // Since we are using function() below because of arguments, TS won't automatically do a _this for those functions.
80+ var _this = this ;
81+ promise . cancel = ( ) => {
82+ _this . cancel ( ) ;
83+ } ;
84+ var _then = promise . then ;
85+ promise . then = function ( ) {
86+ var r = _then . apply ( promise , arguments ) ;
87+ _this . fixupAnimationPromise ( r ) ;
88+ return r ;
89+ } ;
90+ var _catch = promise . catch ;
91+ promise . catch = function ( ) {
92+ var r = _catch . apply ( promise , arguments ) ;
93+ _this . fixupAnimationPromise ( r ) ;
94+ return r ;
95+ } ;
96+ }
97+
6698 public cancel ( ) : void {
6799 if ( ! this . isPlaying ) {
68100 throw new Error ( "Animation is not currently playing." ) ;
0 commit comments