Skip to content

Commit

Permalink
Fix issue where Firefox Promise then callback can not correctly keep …
Browse files Browse the repository at this point in the history
…track of its key
  • Loading branch information
richtr committed Oct 4, 2016
1 parent 2fcc931 commit 1db4fc2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
39 changes: 22 additions & 17 deletions examples/js/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ GLTFShader.prototype.update = function( scene, camera ) {

}

}.bind(this));
}.bind( this ));

};

Expand Down Expand Up @@ -569,33 +569,38 @@ var _each = function( object, callback, thisObj ) {
results = [];

var length = object.length;
for ( let idx = 0; idx < length; idx ++ ) {
let value = callback.call( thisObj || this, object[ idx ], idx );
fns.push( value );
if ( value && value instanceof Promise ) {
value.then( function( value ) {
for ( var idx = 0; idx < length; idx ++ ) {
var value = callback.call( thisObj || this, object[ idx ], idx );
if ( value ) {
fns.push( value );
if ( value instanceof Promise ) {
value.then( function( key, value ) {
results[ idx ] = value;
}.bind( this, key ));
} else {
results[ idx ] = value;
});
} else {
results[ idx ] = value;
}
}

}

} else {


results = {};

for ( let key in object ) {
for ( var key in object ) {
if ( object.hasOwnProperty( key ) ) {
let value = callback.call( thisObj || this, object[ key ], key );
fns.push( value );
if ( value && value instanceof Promise ) {
value.then( function( value ) {
var value = callback.call( thisObj || this, object[ key ], key );
if ( value ) {
fns.push( value );
if ( value instanceof Promise ) {
value.then( function( key, value ) {
results[ key ] = value;
}.bind( this, key ));
} else {
results[ key ] = value;
});
} else {
results[ key ] = value;
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions examples/webgl_loader_gltf.html
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,22 @@
addLights:true,
addGround:true,
shadows:true
},
{
name : "tbox",
url : "./models/gltf/tbox/%s/tbox.gltf",
cameraPos: new THREE.Vector3(0, 3, 10),
addLights:false,
addGround:false,
shadows:false
},
{
name : "VC",
url : "./models/gltf/VC/%s/VC.gltf",
cameraPos: new THREE.Vector3(0, 3, 10),
addLights:false,
addGround:false,
shadows:false
}
];

Expand Down

0 comments on commit 1db4fc2

Please sign in to comment.