Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to clean up (e.g. unsubscribe from events) #4

Closed
Glavin001 opened this issue Jul 10, 2022 · 3 comments
Closed

Add method to clean up (e.g. unsubscribe from events) #4

Glavin001 opened this issue Jul 10, 2022 · 3 comments

Comments

@Glavin001
Copy link

Why?

So this can be destroyed and cleaned up correctly.

Solution

Unsubscribe these events and potentially others:

canvas.addEventListener( 'click', e=>{
if( stopClick ){
e.stopImmediatePropagation();
stopClick = false;
}
});
canvas.addEventListener( 'pointermove', e=>{
this.update();
this._updateRaycaster( e );
if( !this.data.isDragging ){
this.data.onRayHover( this._ray );
}else{
this.data.onRayMove( this._ray );
canvas.setPointerCapture( e.pointerId ); // Keep receiving events
e.preventDefault();
e.stopPropagation();
}
});
canvas.addEventListener( 'pointerdown', e=>{
this._updateRaycaster( e );
if( this.data.onRayDown( this._ray ) ){
e.preventDefault();
e.stopPropagation();
stopClick = true;
}
} );
canvas.addEventListener( 'pointerup', e=>{
if( this.data.isDragging ){
this.data.stopDrag();
canvas.releasePointerCapture( e.pointerId );
}
});

Glavin001 added a commit to Glavin001/manipulator3d that referenced this issue Jul 10, 2022
@Glavin001
Copy link
Author

Fixed with #7

@sketchpunk
Copy link
Contributor

changes related applied to v0.0.0.6 and live on npm.

@Glavin001
Copy link
Author

Fixed with f84f377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants