Boutique icon indicating copy to clipboard operation
Boutique copied to clipboard

i can't get items at the real time,can tell me where is wrong

Open zidonJ opened this issue 1 year ago • 4 comments

@MainActor func local() -> ReadModel? {

    let read:ReadModel? = parse.items.sfi(0)
    return read
}

zidonJ avatar Dec 18 '23 09:12 zidonJ

i got it-> loadStoreTask not complete, did boutique have a real time way get the local data or offer a loadStoreTask complete handler

zidonJ avatar Dec 18 '23 10:12 zidonJ

Hi @zidonJ, I'm not 100% sure I understand the problem you're running into so please correct me if this isn't the question you're hoping to answer. If you need to find out whether a Store has finished loading it's items you can use the Store's .itemsHaveLoaded() function to know when the Task has completed.

The example below shows the recommended way to await a Store to see if it's loaded, after which you can update your View's state based on the Store having loaded.

struct ItemListView: View {
    @State private var itemsHaveLoaded = false

    var body: some View {
        VStack {
            AlwaysVisibleBanner()

            if self.itemsHaveLoaded {
                if self.items.isEmpty {
                    EmptyStateView()
                } else {
                    ItemView(items: self.items)
                }
            } else {
                LoadingStateView()
            }
        }
        .task({
            try await self.itemsController.items.itemsHaveLoaded()
            self.itemsHaveLoaded = true
        })
    }
}

mergesort avatar Dec 20 '23 00:12 mergesort

thank you, i Understood. but i have an another question that why not offer a interface to get any cacheKey data ,private let storageEngine can not get it. should i keey the storageEngine.

zidonJ avatar Dec 20 '23 01:12 zidonJ

@zidonJ Not allowing users to access the StorageEngine from Boutique an intentional design choice. As per principle 1 & 2 discussed in #19, there is only one API to insert or remove items from Boutique. This ensures consistency between what models are in memory and what models are on disk, and means that users are always interacting at the model layer rather than trying to think of Boutique as a database that they have to architect their app around. Beyond that, the data that your CacheKeys are based on will come from your models, which means any queries you want to do in Boutique should be doable without ever needing to interface with a CacheKey.

Hope that helps answer your question!

mergesort avatar Dec 21 '23 16:12 mergesort