Created
September 6, 2022 21:22
-
-
Save tobiu/335351184db3ed9c3ef4d84449f646cf to your computer and use it in GitHub Desktop.
Neo.component.Canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from './Base.mjs'; | |
/** | |
* @class Neo.component.Canvas | |
* @extends Neo.component.Base | |
*/ | |
class Canvas extends Component { | |
static getConfig() {return { | |
/** | |
* @member {String} className='Neo.component.Canvas' | |
* @protected | |
*/ | |
className: 'Neo.component.Canvas', | |
/** | |
* @member {String} ntype='canvas' | |
* @protected | |
*/ | |
ntype: 'canvas', | |
/** | |
* @member {Boolean} offscreen=true | |
*/ | |
offscreen: true, | |
/** | |
* Only applicable if offscreen === true. | |
* true once the ownership of the canvas node got transferred to worker.Canvas. | |
* @member {Boolean} offscreenRegistered_=false | |
*/ | |
offscreenRegistered_: false, | |
/** | |
* @member {Object} _vdom={tag: 'canvas'} | |
*/ | |
_vdom: | |
{tag: 'canvas'} | |
}} | |
/** | |
* Triggered after the mounted config got changed | |
* @param {Boolean} value | |
* @param {Boolean} oldValue | |
* @protected | |
*/ | |
afterSetMounted(value, oldValue) { | |
super.afterSetMounted(value, oldValue); | |
let me = this, | |
id = me.getCanvasId(), | |
offscreen = me.offscreen, | |
worker = Neo.currentWorker; | |
if (value && offscreen) { | |
worker.promiseMessage('main', { | |
action : 'getOffscreenCanvas', | |
appName: me.appName, | |
nodeId : id | |
}).then(data => { | |
worker.promiseMessage('canvas', { | |
action: 'registerCanvas', | |
node : data.offscreen, | |
nodeId: id | |
}, [data.offscreen]).then(() => { | |
me.offscreenRegistered = true; | |
}); | |
}); | |
} else if (offscreen) { | |
me.offscreenRegistered = false; | |
} | |
} | |
/** | |
* Override this method when using wrappers (e.g. D3) | |
* @returns {String} | |
*/ | |
getCanvasId() { | |
return this.id; | |
} | |
} | |
Neo.applyClassConfig(Canvas); | |
export default Canvas; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment