Stop rebinding
This commit is contained in:
parent
c4811ee59c
commit
4c51c1a035
1 changed files with 10 additions and 2 deletions
|
|
@ -64,8 +64,10 @@ export const getUniversalRenderingContext = (
|
||||||
};
|
};
|
||||||
canvas.addEventListener('webglcontextlost', handleContextLost, false);
|
canvas.addEventListener('webglcontextlost', handleContextLost, false);
|
||||||
|
|
||||||
|
const boundFunctions = new Map<string | symbol, any>();
|
||||||
|
|
||||||
const contextLostHandler = {
|
const contextLostHandler = {
|
||||||
get: function (target: UniversalRenderingContext, prop: string) {
|
get: function (target: UniversalRenderingContext, prop: string | symbol) {
|
||||||
const value = (target as any)[prop];
|
const value = (target as any)[prop];
|
||||||
|
|
||||||
if (typeof value === 'function') {
|
if (typeof value === 'function') {
|
||||||
|
|
@ -74,7 +76,13 @@ export const getUniversalRenderingContext = (
|
||||||
throw new ContextLostException();
|
throw new ContextLostException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return value.bind(target);
|
let bound = boundFunctions.get(prop);
|
||||||
|
if (bound === undefined) {
|
||||||
|
bound = value.bind(target);
|
||||||
|
boundFunctions.set(prop, bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue