-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
WebGLAnimation: Convert to es6 class #20070
WebGLAnimation: Convert to es6 class #20070
Conversation
Looks like some e2e tests failed... I'll check it out. |
What happens if there are two instances of |
Thanks... in my heart I knew it was wrong 😆 I found a safe solution, we can do a one-time bind to constructor() {
this._context = null;
this._isAnimating = false;
this._animationLoop = null;
this._requestId = null;
// Re-bind the prototype function so that `this` can be used with rAF:
this._onAnimationFrame = this._onAnimationFrame.bind( this );
} |
Fixes unbound requestAnimationFrame callbacks
c9f2106
to
77a26dd
Compare
Now that I know how const _context = Symbol( '_context' );
const _isAnimating = Symbol( '_isAnimating' );
const _animationLoop = Symbol( '_animationLoop' );
const _requestId = Symbol( '_requestId' );
const _onAnimationFrame = Symbol( '_onAnimationFrame' );
class WebGLAnimation {
constructor() {
this[ _context ] = null;
this[ _isAnimating ] = false;
this[ _animationLoop ] = null;
this[ _requestId ] = null;
const scope = this;
this[ _onAnimationFrame ] = function ( time, frame ) {
scope[ _animationLoop ]( time, frame );
scope[ _requestId ] = scope[ _context ].requestAnimationFrame( scope[ _onAnimationFrame ] );
};
}
start() {
if ( this[ _isAnimating ] === true ) return;
if ( this[ _animationLoop ] === null ) return;
this[ _requestId ] = this[ _context ].requestAnimationFrame( this[ _onAnimationFrame ] );
this[ _isAnimating ] = true;
}
stop() {
this[ _context ].cancelAnimationFrame( this[ _requestId ] );
this[ _isAnimating ] = false;
}
setAnimationLoop( callback ) {
this[ _animationLoop ] = callback;
}
setContext( value ) {
this[ _context ] = value;
}
}
export { WebGLAnimation }; IE11 doesn't support And, in a distant future... going from |
I do not know what are the performance implications of using |
👍 👍 I think that should work, I'll glitch a benchmark so that we can start looking at performance. |
Alright, hopefully this is a decent starting point! https://button-knotty-tugboat.glitch.me I was able to get some coverage on macOS and iOS... Looks like Chrome and iOS Safari handle all the es6 techniques pretty evenly. Interestingly, desktop Safari actually favors the symbol and string techniques. But Firefox penalizes both of those techniques heavily.
|
Quick heads-up, I moved that benchmark to here and added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closing. We've agreed in #19986 to not change/refactor the code in |
Supports #19986