@maverick-js/signals
Advanced tools
Comparing version 5.0.0 to 5.0.1
// src/scheduler.ts | ||
function createScheduler() { | ||
let i = 0, j = 0, flushing = false, tasks = [], microtask = Promise.resolve(), beforeTasks = [], afterTasks = []; | ||
let i = 0, j = 0, flushing = false, tasks = [], beforeTasks = [], afterTasks = []; | ||
const enqueue = (task) => { | ||
@@ -35,3 +35,2 @@ tasks.push(task); | ||
return { | ||
tick: microtask, | ||
enqueue, | ||
@@ -208,2 +207,3 @@ flush: scheduleFlush, | ||
effectResult && currentScope && onDispose(effectResult); | ||
effectResult = null; | ||
}, | ||
@@ -221,4 +221,3 @@ true ? { id: options?.id ?? "effect", fallback: null } : void 0 | ||
function tick() { | ||
scheduler.flush(); | ||
return scheduler.tick; | ||
scheduler.flushSync(); | ||
} | ||
@@ -225,0 +224,0 @@ function isWriteSignal(fn) { |
// src/scheduler.ts | ||
function createScheduler() { | ||
let i = 0, j = 0, flushing = false, tasks = [], microtask = Promise.resolve(), beforeTasks = [], afterTasks = []; | ||
let i = 0, j = 0, flushing = false, tasks = [], beforeTasks = [], afterTasks = []; | ||
const enqueue = (task) => { | ||
@@ -35,3 +35,2 @@ tasks.push(task); | ||
return { | ||
tick: microtask, | ||
enqueue, | ||
@@ -206,2 +205,3 @@ flush: scheduleFlush, | ||
effectResult && currentScope && onDispose(effectResult); | ||
effectResult = null; | ||
}, | ||
@@ -219,4 +219,3 @@ false ? { id: options?.id ?? "effect", fallback: null } : void 0 | ||
function tick() { | ||
scheduler.flush(); | ||
return scheduler.tick; | ||
scheduler.flushSync(); | ||
} | ||
@@ -223,0 +222,0 @@ function isWriteSignal(fn) { |
@@ -62,4 +62,4 @@ /** | ||
* | ||
* // Wait for flush to complete. | ||
* await scheduler.tick; | ||
* // Run a synchronous flush. | ||
* await scheduler.flushSync(); | ||
* ``` | ||
@@ -188,3 +188,2 @@ */ | ||
export declare type Scheduler = { | ||
tick: Promise<void>; | ||
enqueue: (task: ScheduledTask) => void; | ||
@@ -236,9 +235,8 @@ flush: () => void; | ||
/** | ||
* Tasks are batched onto the microtask queue. This means only the last write of multiple write | ||
* actions performed in the same execution window is applied. You can wait for the microtask | ||
* queue to be flushed before writing a new value so it takes effect. | ||
* By default, signal updates are batched on the microtask queue which is an async process. You can | ||
* flush the queue synchronously to get the latest updates by calling `tick()`. | ||
* | ||
* @see {@link https://github.com/maverick-js/signals#tick} | ||
*/ | ||
export declare function tick(): Promise<void>; | ||
export declare function tick(): void; | ||
@@ -245,0 +243,0 @@ /** |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "module": "dist/prod/index.js", |
@@ -39,3 +39,3 @@ # Signals | ||
root(async (dispose) => { | ||
root((dispose) => { | ||
// Create - all types supported (string, array, object, etc.) | ||
@@ -59,9 +59,9 @@ const $m = signal(1); | ||
// Wait a tick so update is applied and effect is run. | ||
await tick(); | ||
// Flush queue synchronously so effect is run. | ||
// Otherwise, computations will be batched and run on the microtask queue. | ||
tick(); | ||
$b.next((prev) => prev + 5); // logs `15` inside effect | ||
// Wait a tick so effect runs last update. | ||
await tick(); | ||
tick(); | ||
@@ -202,7 +202,7 @@ // Nothing has changed - no re-compute. | ||
$a.set(20); | ||
await tick(); | ||
tick(); | ||
console.log($c()); // logs 30 | ||
$b.set(20); | ||
await tick(); | ||
tick(); | ||
console.log($c()); // logs 40 | ||
@@ -309,5 +309,4 @@ | ||
Tasks are batched onto the microtask queue. This means only the last write of multiple write | ||
actions performed in the same execution window is applied. You can wait for the microtask | ||
queue to be flushed before writing a new value so it takes effect. | ||
By default, signal updates are batched on the microtask queue which is an async process. You can | ||
flush the queue synchronously to get the latest updates by calling `tick()`. | ||
@@ -334,5 +333,5 @@ > **Note** | ||
$a.set(10); | ||
await tick(); | ||
tick(); | ||
$a.set(20); | ||
await tick(); | ||
tick(); | ||
$a.set(30); | ||
@@ -368,3 +367,3 @@ ``` | ||
source.set([3, 2, 1]); | ||
await tick(); | ||
tick(); | ||
@@ -413,3 +412,3 @@ // Notice the index `i` remains fixed but `id` has updated. | ||
await tick(); | ||
tick(); | ||
@@ -416,0 +415,0 @@ // No nodes were created/destroyed, simply nodes at index 0 and 1 switched. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59458
1201
742