diff --git a/src/store.ts b/src/store.ts index 4e6d9a83..93bb966d 100644 --- a/src/store.ts +++ b/src/store.ts @@ -132,7 +132,7 @@ export function useStore(selector, options: SelectorOptions = {}): any { __destroy.call(component, parent); }; - if (typeof result !== "object") { + if (typeof result !== "object" || result === null) { return result; } return new Proxy(result, { diff --git a/tests/store_hooks.test.ts b/tests/store_hooks.test.ts index cfa19548..9b117d77 100644 --- a/tests/store_hooks.test.ts +++ b/tests/store_hooks.test.ts @@ -49,10 +49,13 @@ describe("connecting a component to store", () => { }); test("useStore can observe primitive types and call onUpdate", async () => { - const state = { isBoolean: false }; + const state = { isBoolean: false, nullValue: null }; const actions = { setTrue({ state }) { state.isBoolean = true; + }, + setNotNull({ state }) { + state.nullValue = "ok"; } }; const store = new Store({ state, actions }); @@ -61,8 +64,10 @@ describe("connecting a component to store", () => { static template = xml`
ok + not null
`; isBoolean: boolean; + nullValue: string; constructor() { super(); this.isBoolean = useStore(state => state.isBoolean, { @@ -70,6 +75,11 @@ describe("connecting a component to store", () => { this.isBoolean = isBoolean; } }); + this.nullValue = useStore(state => state.nullValue, { + onUpdate: nullValue => { + this.nullValue = nullValue; + } + }); } } @@ -82,6 +92,10 @@ describe("connecting a component to store", () => { store.dispatch("setTrue"); await nextTick(); expect(fixture.innerHTML).toBe("
ok
"); + + store.dispatch("setNotNull"); + await nextTick(); + expect(fixture.innerHTML).toBe("
oknot null
"); }); test("map works on the result of useStore when the resulting array changes for a bigger one", async () => {