-
Hi
private load(): void {
this.logger_.logMethod?.('load');
const newData = localJsonStorage.getItem<Dictionary | null>(this.localStorageKey__, null, this.config__.version);
if (newData == null) {
// check exists in local storage
if (localStorage.getItem(localJsonStorage.key_(this.localStorageKey__, this.config__.version)) === null) {
this.logger_.logOther?.('no_data');
return;
}
// data not parsed.
this.logger_.error('load', 'data_not_parsed', {localStorageKey: this.localStorageKey__});
return;
}
const rev = +localJsonStorage.getItem<string>(this.revLocalStorageKey__, '0', this.config__.version);
if (rev === this.rev__) {
// data not modified
this.logger_.logOther?.('data_not_modified', newData);
return;
}
this.logger_.logOther?.('loaded_modified_data', newData);
this.store.data = newData;
this.rev__ = rev;
} ui: <section>
<template x-for="product in productList" :key="product.id">
<div
x-data="productItem(category, product.id)"
>
<img class="w-full select-none rounded-xl" :src="window.globalConfig.cdn.basePath + product.image.id" :alt="product.title.fa" />
<div class="p-2 flex flex-col grow">
<h2 class="text-titleMedium">
<span x-text="product.title.fa"></span> <span class="text-labelSmall text-secondary">(<span x-text="unit.fa"></span>)</span>
</h2>
<p class="text-labelSmall text-secondary grow">
<span x-text="l10n.number(product.countInBox)"></span> <span x-text="'عدد در ' + package.fa"></span>
</p>
<!-- price -->
<div x-show="product.available" :class="{ 'line-through opacity-60': $store.userProfile.data, 'hidden': product.finalPrice === product.originalPrice }" class="text-end text-titleMedium">
<span x-text="l10n.number(product.originalPrice)"></span> {% alwatrIcon "extra/toman", "size-[1em] opacity-80" %}
</div>
<div x-show="product.available" class="text-end text-titleMedium">
<span x-text="l10n.number(product.finalPrice)"></span> {% alwatrIcon "extra/toman", "size-[1em] opacity-80" %}
</div>
<div class="mt-2">
<button
x-show="!product.available"
class="button-base mt-2 w-full rounded-full border border-error text-error pointer-events-none text-labelLarge"
>
{% alwatrIcon "close", "size-[1.5em]" %}
<span>عدم موجودی</span>
</button>
<button
class="button-primary mt-2 w-full"
x-show="!selected"
@click.throttle="window.cart.add(category, product.id); selected = true;"
>
{% alwatrIcon "add", "size-[1.5em]" %}
<span>افزودن</span>
</button>
<button
x-show="selected"
class="button-base mt-2 w-full rounded-full border border-green-900 text-green-900 pointer-events-none text-labelLarge"
>
{% alwatrIcon "done_all", "size-[1.5em]" %}
<span>اضافه شده</span>
</button>
</div>
</div>
</div>
</template>
</section> the selected is from alpine data: alpine.data('productItem', (category: ProductCategory, productId: string) => {
const selected = cartStore.store.findIndex(category as ProductCategory, productId) !== -1;
return {
selected,
};
}); thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
also in other page that's contract with same store, I'm have issue for render cards from alpine store |
Beta Was this translation helpful? Give feedback.
-
and when I'm disable pre-render all things is fine |
Beta Was this translation helpful? Give feedback.
-
I honestly cannot tell what this is trying to do or what you are saying isn't working. You do what and what doesn't change? You can just use But I think the main issue is that your data is locking in a So alpine.data('productItem', (category: ProductCategory, productId: string) => {
- const selected = cartStore.store.findIndex(category as ProductCategory, productId) !== -1;
return {
- selected,
+ get selected() {
+ return cartStore.store.findIndex(category as ProductCategory, productId) !== -1;
+ }
};
}); I don't really know why this is doing a |
Beta Was this translation helpful? Give feedback.
I honestly cannot tell what this is trying to do or what you are saying isn't working.
You do what and what doesn't change?
You can just use
Alpine.$persist
to handle syncing to local storage instead of writing all that monstrous code there.But I think the main issue is that your data is locking in a
selected
value when it runs, and you never change it.So
I don't rea…