You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all! I am writing an online store and depending on the authentication state the cart can be stored either in localstorage or sent to the server. I have two implementations of the ICartStore interface: BackendCartStore and LocalStorageCartStore
I also have a Catalog component that needs cart information
I want to achieve a behavior where the page is loaded in parallel with the request to the server, putting as default LocalStorageCartStore, and then if BackendCartStore is loaded, swap one for the other. However, I can achieve this only with Show, essentially just stopping the thread and waiting for a response from the server, which slows down the application a lot. Otherwise I just get one of the storages with about 50/50 probability, which is then not updated in any way. I guess it depends on whether a response comes from the server while the components are rendering
I tried it:
use {initialState: LocalStorageCartStore} in createResource
wrapping the store in < Card cartStore={() => cartStore()} />
use const mergedProps = mergeProps({cartStore: LocalStorageCartStore}, props)
But none of this replaces LocalStorageCartStore with BackendCartStore when a response comes from the server. Is there any way to accomplish this at all, or am I obliged to use Show
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all! I am writing an online store and depending on the authentication state the cart can be stored either in localstorage or sent to the server. I have two implementations of the ICartStore interface: BackendCartStore and LocalStorageCartStore
I also have a Catalog component that needs cart information
I want to achieve a behavior where the page is loaded in parallel with the request to the server, putting as default LocalStorageCartStore, and then if BackendCartStore is loaded, swap one for the other. However, I can achieve this only with Show, essentially just stopping the thread and waiting for a response from the server, which slows down the application a lot. Otherwise I just get one of the storages with about 50/50 probability, which is then not updated in any way. I guess it depends on whether a response comes from the server while the components are rendering
I tried it:
{initialState: LocalStorageCartStore}
in createResource< Card cartStore={() => cartStore()} />
const mergedProps = mergeProps({cartStore: LocalStorageCartStore}, props)
But none of this replaces LocalStorageCartStore with BackendCartStore when a response comes from the server. Is there any way to accomplish this at all, or am I obliged to use Show
Beta Was this translation helpful? Give feedback.
All reactions