Bläddra i källkod

Fixed issue with promise polyfill

David Catuhe 7 år sedan
förälder
incheckning
32aecc8eae

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 14601 - 14601
Playground/babylon.d.txt


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 14369 - 14369
dist/preview release/babylon.d.ts


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 28 - 28
dist/preview release/babylon.js


+ 20 - 0
dist/preview release/babylon.max.js

@@ -10180,6 +10180,19 @@ var BABYLON;
                 this._reject(e);
             }
         }
+        Object.defineProperty(InternalPromise.prototype, "_result", {
+            get: function () {
+                return this._resultValue;
+            },
+            set: function (value) {
+                this._resultValue = value;
+                if (this._parent && this._parent._result === undefined) {
+                    this._parent._result = value;
+                }
+            },
+            enumerable: true,
+            configurable: true
+        });
         InternalPromise.prototype.catch = function (onRejected) {
             return this.then(undefined, onRejected);
         };
@@ -10190,6 +10203,7 @@ var BABYLON;
             newPromise._onRejected = onRejected;
             // Composition
             this._children.push(newPromise);
+            newPromise._parent = this;
             if (this._state !== PromiseStates.Pending) {
                 BABYLON.Tools.SetImmediate(function () {
                     if (_this._state === PromiseStates.Fulfilled || _this._rejectWasConsumed) {
@@ -10198,6 +10212,7 @@ var BABYLON;
                             if (returnedValue._state !== undefined) {
                                 var returnedPromise = returnedValue;
                                 newPromise._children.push(returnedPromise);
+                                returnedPromise._parent = newPromise;
                                 newPromise = returnedPromise;
                             }
                             else {
@@ -10213,7 +10228,11 @@ var BABYLON;
             return newPromise;
         };
         InternalPromise.prototype._moveChildren = function (children) {
+            var _this = this;
             (_a = this._children).push.apply(_a, children.splice(0, children.length));
+            this._children.forEach(function (child) {
+                child._parent = _this;
+            });
             if (this._state === PromiseStates.Fulfilled) {
                 for (var _i = 0, _b = this._children; _i < _b.length; _i++) {
                     var child = _b[_i];
@@ -10239,6 +10258,7 @@ var BABYLON;
                     if (returnedValue._state !== undefined) {
                         // Transmit children
                         var returnedPromise = returnedValue;
+                        returnedPromise._parent = this;
                         returnedPromise._moveChildren(this._children);
                         value = returnedPromise._result;
                     }

+ 20 - 0
dist/preview release/babylon.no-module.max.js

@@ -10147,6 +10147,19 @@ var BABYLON;
                 this._reject(e);
             }
         }
+        Object.defineProperty(InternalPromise.prototype, "_result", {
+            get: function () {
+                return this._resultValue;
+            },
+            set: function (value) {
+                this._resultValue = value;
+                if (this._parent && this._parent._result === undefined) {
+                    this._parent._result = value;
+                }
+            },
+            enumerable: true,
+            configurable: true
+        });
         InternalPromise.prototype.catch = function (onRejected) {
             return this.then(undefined, onRejected);
         };
@@ -10157,6 +10170,7 @@ var BABYLON;
             newPromise._onRejected = onRejected;
             // Composition
             this._children.push(newPromise);
+            newPromise._parent = this;
             if (this._state !== PromiseStates.Pending) {
                 BABYLON.Tools.SetImmediate(function () {
                     if (_this._state === PromiseStates.Fulfilled || _this._rejectWasConsumed) {
@@ -10165,6 +10179,7 @@ var BABYLON;
                             if (returnedValue._state !== undefined) {
                                 var returnedPromise = returnedValue;
                                 newPromise._children.push(returnedPromise);
+                                returnedPromise._parent = newPromise;
                                 newPromise = returnedPromise;
                             }
                             else {
@@ -10180,7 +10195,11 @@ var BABYLON;
             return newPromise;
         };
         InternalPromise.prototype._moveChildren = function (children) {
+            var _this = this;
             (_a = this._children).push.apply(_a, children.splice(0, children.length));
+            this._children.forEach(function (child) {
+                child._parent = _this;
+            });
             if (this._state === PromiseStates.Fulfilled) {
                 for (var _i = 0, _b = this._children; _i < _b.length; _i++) {
                     var child = _b[_i];
@@ -10206,6 +10225,7 @@ var BABYLON;
                     if (returnedValue._state !== undefined) {
                         // Transmit children
                         var returnedPromise = returnedValue;
+                        returnedPromise._parent = this;
                         returnedPromise._moveChildren(this._children);
                         value = returnedPromise._result;
                     }

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 28 - 28
dist/preview release/babylon.worker.js


+ 20 - 0
dist/preview release/es6.js

@@ -10147,6 +10147,19 @@ var BABYLON;
                 this._reject(e);
             }
         }
+        Object.defineProperty(InternalPromise.prototype, "_result", {
+            get: function () {
+                return this._resultValue;
+            },
+            set: function (value) {
+                this._resultValue = value;
+                if (this._parent && this._parent._result === undefined) {
+                    this._parent._result = value;
+                }
+            },
+            enumerable: true,
+            configurable: true
+        });
         InternalPromise.prototype.catch = function (onRejected) {
             return this.then(undefined, onRejected);
         };
@@ -10157,6 +10170,7 @@ var BABYLON;
             newPromise._onRejected = onRejected;
             // Composition
             this._children.push(newPromise);
+            newPromise._parent = this;
             if (this._state !== PromiseStates.Pending) {
                 BABYLON.Tools.SetImmediate(function () {
                     if (_this._state === PromiseStates.Fulfilled || _this._rejectWasConsumed) {
@@ -10165,6 +10179,7 @@ var BABYLON;
                             if (returnedValue._state !== undefined) {
                                 var returnedPromise = returnedValue;
                                 newPromise._children.push(returnedPromise);
+                                returnedPromise._parent = newPromise;
                                 newPromise = returnedPromise;
                             }
                             else {
@@ -10180,7 +10195,11 @@ var BABYLON;
             return newPromise;
         };
         InternalPromise.prototype._moveChildren = function (children) {
+            var _this = this;
             (_a = this._children).push.apply(_a, children.splice(0, children.length));
+            this._children.forEach(function (child) {
+                child._parent = _this;
+            });
             if (this._state === PromiseStates.Fulfilled) {
                 for (var _i = 0, _b = this._children; _i < _b.length; _i++) {
                     var child = _b[_i];
@@ -10206,6 +10225,7 @@ var BABYLON;
                     if (returnedValue._state !== undefined) {
                         // Transmit children
                         var returnedPromise = returnedValue;
+                        returnedPromise._parent = this;
                         returnedPromise._moveChildren(this._children);
                         value = returnedPromise._result;
                     }

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 31 - 31
dist/preview release/viewer/babylon.viewer.js


+ 23 - 1
dist/preview release/viewer/babylon.viewer.max.js

@@ -10268,6 +10268,19 @@ var BABYLON;
                 this._reject(e);
             }
         }
+        Object.defineProperty(InternalPromise.prototype, "_result", {
+            get: function () {
+                return this._resultValue;
+            },
+            set: function (value) {
+                this._resultValue = value;
+                if (this._parent && this._parent._result === undefined) {
+                    this._parent._result = value;
+                }
+            },
+            enumerable: true,
+            configurable: true
+        });
         InternalPromise.prototype.catch = function (onRejected) {
             return this.then(undefined, onRejected);
         };
@@ -10278,6 +10291,7 @@ var BABYLON;
             newPromise._onRejected = onRejected;
             // Composition
             this._children.push(newPromise);
+            newPromise._parent = this;
             if (this._state !== PromiseStates.Pending) {
                 BABYLON.Tools.SetImmediate(function () {
                     if (_this._state === PromiseStates.Fulfilled || _this._rejectWasConsumed) {
@@ -10286,6 +10300,7 @@ var BABYLON;
                             if (returnedValue._state !== undefined) {
                                 var returnedPromise = returnedValue;
                                 newPromise._children.push(returnedPromise);
+                                returnedPromise._parent = newPromise;
                                 newPromise = returnedPromise;
                             }
                             else {
@@ -10301,7 +10316,11 @@ var BABYLON;
             return newPromise;
         };
         InternalPromise.prototype._moveChildren = function (children) {
+            var _this = this;
             (_a = this._children).push.apply(_a, children.splice(0, children.length));
+            this._children.forEach(function (child) {
+                child._parent = _this;
+            });
             if (this._state === PromiseStates.Fulfilled) {
                 for (var _i = 0, _b = this._children; _i < _b.length; _i++) {
                     var child = _b[_i];
@@ -10327,6 +10346,7 @@ var BABYLON;
                     if (returnedValue._state !== undefined) {
                         // Transmit children
                         var returnedPromise = returnedValue;
+                        returnedPromise._parent = this;
                         returnedPromise._moveChildren(this._children);
                         value = returnedPromise._result;
                     }
@@ -106288,7 +106308,9 @@ var BABYLON;
             GLTFLoader.prototype._loadAnimationChannelAsync = function (context, animationContext, animation, channel, babylonAnimationGroup) {
                 var _this = this;
                 var targetNode = GLTFLoader._GetProperty(context + "/target/node", this._gltf.nodes, channel.target.node);
-                if (!targetNode._babylonMesh) {
+                // Ignore animations that have no animation targets.
+                if ((channel.target.path === "weights" /* WEIGHTS */ && !targetNode._numMorphTargets) ||
+                    (channel.target.path !== "weights" /* WEIGHTS */ && !targetNode._babylonAnimationTargets)) {
                     return Promise.resolve();
                 }
                 // Ignore animations targeting TRS of skinned nodes.

+ 22 - 2
src/Tools/babylon.promise.ts

@@ -15,13 +15,26 @@ module BABYLON {
 
     class InternalPromise<T> {
         private _state = PromiseStates.Pending;
-        private _result?: Nullable<T>;
+        private _resultValue?: Nullable<T>;
         private _reason: any;
         private _children = new Array<InternalPromise<T>>();
+        private _parent: Nullable<InternalPromise<T>>;
         private _onFulfilled?: (fulfillment?: Nullable<T>) => Nullable<InternalPromise<T>> | T;
         private _onRejected?: (reason: any) => void;
         private _rejectWasConsumed = false;
 
+        private get _result(): Nullable<T> | undefined {
+            return this._resultValue;
+        }
+
+        private set _result(value: Nullable<T> | undefined) {
+            this._resultValue = value;
+
+            if (this._parent && this._parent._result === undefined) {
+                this._parent._result = value;
+            }
+        }
+
         public constructor(resolver?: (
             resolve: (value?: Nullable<T>) => void,
             reject: (reason: any) => void
@@ -53,6 +66,7 @@ module BABYLON {
 
             // Composition
             this._children.push(newPromise);
+            newPromise._parent = this;
 
             if (this._state !== PromiseStates.Pending) {
                 Tools.SetImmediate(() => {
@@ -63,6 +77,7 @@ module BABYLON {
                             if ((<InternalPromise<T>>returnedValue)._state !== undefined) {
                                 let returnedPromise = returnedValue as InternalPromise<T>;
                                 newPromise._children.push(returnedPromise);
+                                returnedPromise._parent = newPromise;
                                 newPromise = returnedPromise;
                             } else {
                                 newPromise._result = (<T>returnedValue);
@@ -80,6 +95,10 @@ module BABYLON {
         private _moveChildren(children: InternalPromise<T>[]): void {
             this._children.push(...children.splice(0, children.length));
 
+            this._children.forEach(child => {
+                child._parent = this;
+            });
+
             if (this._state === PromiseStates.Fulfilled) {
                 for (var child of this._children) {
                     child._resolve(this._result);
@@ -104,8 +123,9 @@ module BABYLON {
                     if ((<InternalPromise<T>>returnedValue)._state !== undefined) {
                         // Transmit children
                         let returnedPromise = returnedValue as InternalPromise<T>;
-
+                        returnedPromise._parent = this;
                         returnedPromise._moveChildren(this._children);
+
                         value = returnedPromise._result;
                     } else {
                         value = <T>returnedValue;

+ 29 - 0
tests/unit/babylon/src/Tools/babylon.promise.tests.ts

@@ -217,6 +217,35 @@ describe('Babylon.Promise', function () {
                     }
                 });
         });
+
+        it('should correctly handle then multiple times', (done) => {
+            var promise = Promise.resolve().then(function () {
+                return new Promise(function (resolve) {
+                    setTimeout(function () {
+                        resolve(123);
+                    }, 100);
+                });
+            });
+            
+            promise.then(function (result1) {
+                try {
+                    result1.should.be.equal(123);
+                }
+                catch(error) {
+                    done(error);
+                }
+                return promise.then(function (result2) {
+                    try {
+                        result2.should.be.equal(123);
+                        done();
+                    }
+                    catch(error) {
+                        done(error);
+                    }
+                });
+            });    
+        });        
+
     });
 
     describe('#Multiple children', () => {