Skip to content

Commit

Permalink
Refactor event sequence to avoid confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
pchen66 committed Apr 23, 2020
1 parent b0b7b43 commit 4f47703
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/panorama/PanoMomentPanorama.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function PanoMomentPanorama ( identifier, options = {} ) {
// Event Listeners
this.addEventListener( 'panolens-camera', data => this.onPanolensCamera( data ) );
this.addEventListener( 'panolens-controls', data => this.onPanolensControls( data ) );
this.addEventListener( 'enter-start', () => this.enter() );
this.addEventListener( 'enter-fade-start', () => this.enter() );
this.addEventListener( 'leave-complete', () => this.leave() );
this.addEventListener( PANOMOMENT.LOAD, () => this.disableControl() );
this.addEventListener( PANOMOMENT.READY, () => this.enableControl() );
Expand Down
14 changes: 13 additions & 1 deletion src/panorama/Panorama.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ Panorama.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
*/
this.dispatchEvent( { type: 'loaded' } );

/**
* Panorama is ready to go
* @event Panorama#ready
* @type {object}
*/
this.dispatchEvent( { type: 'ready' } );

},

/**
Expand Down Expand Up @@ -629,7 +636,12 @@ Panorama.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {

if ( this.loaded ) {

this.fadeIn( duration );
/**
* Panorama is ready to go
* @event Panorama#ready
* @type {object}
*/
this.dispatchEvent( { type: 'ready' } );

} else {

Expand Down
22 changes: 7 additions & 15 deletions src/viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ Viewer.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype

} else {

ep.onEnter();
ep.fadeIn();

}

Expand All @@ -359,7 +359,7 @@ Viewer.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype

const onLeaveComplete = () => {

ep.onEnter();
ep.fadeIn();
lp.removeEventListener( 'leave-complete', onLeaveComplete );

};
Expand All @@ -368,25 +368,17 @@ Viewer.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype

}

if( ep.loaded ) {
const onReady = () => {

onSwitch();
ep.removeEventListener( 'ready', onReady );

} else {

const onLoaded = () => {

onSwitch();
ep.removeEventListener( 'loaded', onLoaded );

};

ep.addEventListener( 'loaded', onLoaded );
ep.load();
};

}
ep.addEventListener( 'ready', onReady );

this.panorama = ep;
this.panorama.onEnter();

}

Expand Down

0 comments on commit 4f47703

Please sign in to comment.