mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] utils: move batched from reactivity to utils
This commit is contained in:
committed by
Aaron Bohy
parent
b33471e819
commit
6d9ed0d62f
+19
-1
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user