mantou132 / gem

💎 Lightweight WebApp development library using custom elements
https://gemjs.org
MIT License
19 stars 2 forks source link

[gem] can't update when render fail after #194

Closed mantou132 closed 2 months ago

mantou132 commented 2 months ago
let microtaskSet = new Set();
function addMicrotask(func) {
  if (typeof func !== 'function') return;
  if (!microtaskSet.size) {
    // delayed execution callback after updating store
    globalThis.queueMicrotask(() => {
      const set = microtaskSet
      microtaskSet  = new Set();
      set .forEach((f) => f());
    });
  }
  microtaskSet.delete(func);
  microtaskSet.add(func);
}
addMicrotask(() => { throw new Error() })
addMicrotask(() => console.log(1))