-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Assume we are in a store where product information is retrieved from API based on the basket the user has.
export const basket: Asyncable<Basket> = asyncable(
load_basket,
save_basket,
);
async function init_products(basket: Promise<Basket>) {}
export const products: Asyncable<Products> = asyncable(
init_products,
undefined,
[basket]
);
Basically, products async manages data from API and depends on what basket contains. products should only fetch what it still does not have from basket (i.e. given a change to basket, I need to compute the delta and only fetch the missing data points from the API).
I am struggling to implement init_products. Specifically:
init_productsreceives the state of the basket, but it has no access to the current state ofproducts. Therefore, it cannot optimize API fetches based on the products it already has on changes to basket.update_productsis not defined (/ never used) because this store is not used directly - its use is derived from what basket has (or at least I was unable to makeasyncablecall it by changingbasket.- I can not use
await products.get()insideinit_productsas it is circular.
Is there an idiom to achieve this?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request