diff --git a/src/store.ts b/src/store.ts index 289e99e1..4e6d9a83 100644 --- a/src/store.ts +++ b/src/store.ts @@ -141,6 +141,9 @@ export function useStore(selector, options: SelectorOptions = {}): any { }, set(target, k, v) { throw new Error("Store state should only be modified through actions"); + }, + has(target, k) { + return k in result; } }); } diff --git a/tests/store_hooks.test.ts b/tests/store_hooks.test.ts index b8684289..cfa19548 100644 --- a/tests/store_hooks.test.ts +++ b/tests/store_hooks.test.ts @@ -84,6 +84,38 @@ describe("connecting a component to store", () => { expect(fixture.innerHTML).toBe("
ok
"); }); + test("map works on the result of useStore when the resulting array changes for a bigger one", async () => { + const state = { smallerArray: [1], biggerArray: [2, 3], useSmallArray: true }; + const store = new Store({ state }); + + class App extends Component { + static template = xml`
`; + storeProps = { + array: useStore(state => { + if (state.useSmallArray) { + return state.smallerArray; + } + return state.biggerArray; + }) + }; + get mapAdd() { + return this.storeProps.array.map(a => { + return a + 1; + }); + } + } + + (env).store = store; + const app = new App(); + + await app.mount(fixture); + expect(fixture.innerHTML).toBe("
2
"); + + store.state.useSmallArray = false; + await nextTick(); + expect(fixture.innerHTML).toBe("
3,4
"); + }); + test("throw error if no store is found", async () => { class App extends Component { static template = xml`
`;