@arrow-js/core
Advanced tools
Comparing version
@@ -17,3 +17,2 @@ /** | ||
const nextTicks = new Set(); | ||
let consumingQueue = false; | ||
/** | ||
@@ -36,3 +35,3 @@ * Event listeners that were bound by arrow and should be cleaned up should the | ||
* Queue an item to execute after all synchronous functions have been run. This | ||
* is used for `w()` to ensure multiple dependency mutations tracked on the the | ||
* is used for `w()` to ensure multiple dependency mutations tracked on the | ||
* same expression do not result in multiple calls. | ||
@@ -44,13 +43,21 @@ * @param {CallableFunction} fn | ||
return (newValue, oldValue) => { | ||
function executeQueue() { | ||
// copy the current queues and clear it to allow new items to be added | ||
// during the execution of the current queue. | ||
const queue = Array.from(queueStack); | ||
queueStack.clear(); | ||
const ticks = Array.from(nextTicks); | ||
nextTicks.clear(); | ||
queue.forEach((fn) => fn(newValue, oldValue)); | ||
ticks.forEach((fn) => fn()); | ||
if (queueStack.size) { | ||
// we received new items while executing the queue, so we need to | ||
// execute the queue again. | ||
setTimeout(executeQueue); | ||
} | ||
} | ||
if (!queueStack.size) { | ||
setTimeout(() => { | ||
consumingQueue = true; | ||
queueStack.forEach((fn) => fn(newValue, oldValue)); | ||
queueStack.clear(); | ||
consumingQueue = false; | ||
nextTicks.forEach((fn) => fn()); | ||
nextTicks.clear(); | ||
}); | ||
setTimeout(executeQueue); | ||
} | ||
!consumingQueue && queueStack.add(fn); | ||
queueStack.add(fn); | ||
}; | ||
@@ -57,0 +64,0 @@ } |
{ | ||
"name": "@arrow-js/core", | ||
"version": "1.0.0-alpha.5", | ||
"version": "1.0.0-alpha.6", | ||
"description": "Reactivity without the framework.", | ||
@@ -29,6 +29,6 @@ "author": "Justin Schroeder <justin@wearebraid.com>", | ||
"size-limit": "^4.9.2", | ||
"snowpack": "^3.0.11", | ||
"snowpack": "^3.8.8", | ||
"terser": "^5.5.1", | ||
"ts-jest": "^26.5.0", | ||
"typescript": "^4.1.3" | ||
"typescript": "^4.9.3" | ||
}, | ||
@@ -35,0 +35,0 @@ "engines": { |
@@ -142,3 +142,2 @@ export type DataSourceKey = string | number | symbol | null | ||
const nextTicks: Set<CallableFunction> = new Set() | ||
let consumingQueue = false | ||
@@ -167,3 +166,3 @@ /** | ||
* Queue an item to execute after all synchronous functions have been run. This | ||
* is used for `w()` to ensure multiple dependency mutations tracked on the the | ||
* is used for `w()` to ensure multiple dependency mutations tracked on the | ||
* same expression do not result in multiple calls. | ||
@@ -175,13 +174,21 @@ * @param {CallableFunction} fn | ||
return (newValue?: unknown, oldValue?: unknown) => { | ||
function executeQueue() { | ||
// copy the current queues and clear it to allow new items to be added | ||
// during the execution of the current queue. | ||
const queue = Array.from(queueStack) | ||
queueStack.clear() | ||
const ticks = Array.from(nextTicks) | ||
nextTicks.clear() | ||
queue.forEach((fn) => fn(newValue, oldValue)) | ||
ticks.forEach((fn) => fn()) | ||
if (queueStack.size) { | ||
// we received new items while executing the queue, so we need to | ||
// execute the queue again. | ||
setTimeout(executeQueue) | ||
} | ||
} | ||
if (!queueStack.size) { | ||
setTimeout(() => { | ||
consumingQueue = true | ||
queueStack.forEach((fn) => fn(newValue, oldValue)) | ||
queueStack.clear() | ||
consumingQueue = false | ||
nextTicks.forEach((fn) => fn()) | ||
nextTicks.clear() | ||
}) | ||
setTimeout(executeQueue) | ||
} | ||
!consumingQueue && queueStack.add(fn) | ||
queueStack.add(fn) | ||
} | ||
@@ -188,0 +195,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
353928
0.18%2564
0.55%