[REF] utils: move batched from reactivity to utils

This commit is contained in:
Géry Debongnie
2022-01-10 13:46:11 +01:00
committed by Samuel Degueldre
parent 6091912c54
commit 45f6a8e97a
4 changed files with 48 additions and 27 deletions
+2 -1
View File
@@ -7,7 +7,8 @@ import {
useState,
xml,
} from "../src";
import { batched, reactive } from "../src/reactivity";
import { reactive } from "../src/reactivity";
import { batched } from "../src/utils";
import {
makeDeferred,
makeTestFixture,
+19 -1
View File
@@ -1,4 +1,5 @@
import { EventBus } from "../src/utils";
import { batched, EventBus } from "../src/utils";
import { nextMicroTick } from "./helpers";
describe("event bus behaviour", () => {
test("can subscribe and be notified", () => {
@@ -33,3 +34,20 @@ describe("event bus behaviour", () => {
bus.trigger("event", "hello world");
});
});
describe("batched", () => {
test("callback is called only once after operations", async () => {
let n = 0;
let fn = batched(() => n++);
expect(n).toBe(0);
fn();
fn();
expect(n).toBe(0);
await nextMicroTick();
expect(n).toBe(1);
await nextMicroTick();
expect(n).toBe(1);
});
});