Add instance-map for element dollar-methods

This commit is contained in:
Talia 2022-03-13 11:58:14 +01:00
parent 8d9820cffe
commit 357af9342d
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E

View file

@ -44,13 +44,15 @@ export default Class => {
if (name.startsWith("$")) {
const prop = Object.getOwnPropertyDescriptor(Class.prototype, name)
if (typeof prop.value == "function") {
const queue = []
Class.queues = new WeakMap()
Class.prototype[name.slice(1)] = function(...args) {
const queue = Class.queues.has(this) ? queues.get(this) : []
if (!queue.length) queueMicrotask(() => {
this[name](...queue)
queue.length = 0
})
queue.push(args)
Class.queues.set(this, queue)
}
};
}