Skip to content

Commit

Permalink
Kitchen sink example
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarParra committed Jun 1, 2024
1 parent 315e27b commit 81b741f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion examples/demo-signals/lwc/demoSignals/shopping-cart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $signal, $resource } from "c/signals";
import { $signal, $resource, $effect, useLocalStorage } from "c/signals";
import getShoppingCart from "@salesforce/apex/ShoppingCartController.getShoppingCart";
import updateShoppingCart from "@salesforce/apex/ShoppingCartController.updateShoppingCart";

Expand Down Expand Up @@ -62,10 +62,19 @@ async function updateCartOnTheServer(newCart, previousValue, mutate) {
}
}

const cachedCart = $signal(null, {
storage: useLocalStorage("shoppingCart")
});

export const { data: shoppingCart, mutate: updateCart } = $resource(
getShoppingCart,
{},
{
initialValue: cachedCart.value,
onMutate: updateCartOnTheServer
}
);

$effect(() => {
cachedCart.value = shoppingCart.value;
});

0 comments on commit 81b741f

Please sign in to comment.