mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] reactivity: work even if no callback is given
This commit is contained in:
committed by
Samuel Degueldre
parent
489e20843c
commit
7fdca35a74
+1
-1
@@ -130,7 +130,7 @@ const reactiveCache = new WeakMap<Target, WeakMap<Callback, Reactive>>();
|
||||
* reactive has changed
|
||||
* @returns a proxy that tracks changes to it
|
||||
*/
|
||||
export function reactive<T extends Target>(target: T, callback: Callback): Reactive<T> {
|
||||
export function reactive<T extends Target>(target: T, callback: Callback = () => {}): Reactive<T> {
|
||||
if (!canBeMadeReactive(target)) {
|
||||
throw new Error(`Cannot make the given value reactive`);
|
||||
}
|
||||
|
||||
@@ -60,6 +60,13 @@ describe("Reactivity", () => {
|
||||
expect(Array.isArray(state)).toBe(true);
|
||||
});
|
||||
|
||||
test("work if there are no callback given", () => {
|
||||
const state = reactive({ a: 1 });
|
||||
expect(state.a).toBe(1);
|
||||
state.a = 2;
|
||||
expect(state.a).toBe(2);
|
||||
});
|
||||
|
||||
test("Throw error if value is not proxifiable", () => {
|
||||
expect(() => createReactive(1)).toThrow("Cannot make the given value reactive");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user