logux / client

Logux base components to build web client
https://logux.org/
MIT License
663 stars 47 forks source link

filter.loading promise result should call filter.get() #113

Closed BerkliumBirb closed 3 months ago

BerkliumBirb commented 3 months ago

In next version { isLoading: true } is typed separately from { isLoading: false, isEmpty: boolean, list: ... }. That makes TypeScript freak out when you write something like this:

const filter = createFilter(client, Template, { field: "something" })
await filter.loading
filter.get().list
//            ^ Error: list is not defined on { isLoading: true }

It would be easier to write this instead:

const value = await filter.loading
//        ^: { isLoading: false, isEmpty: boolean, list: ... }
ai commented 3 months ago

const value = await filter.loading

Interesting idea!

Also, next has await loadValue() and ensureLoading (for tests)

ai commented 3 months ago

Adding await filter.loading is hard because of how Promise work and that we use lazy stores.

Please use value = await loadValue(store) it does exactly what do you need.