โ† Back to Home

๐Ÿ›๏ธ Smart Shopping Cart - Auto-Calculating Prices

Change the price, add a coupon, or adjust quantity - everything updates automatically! No manual calculations needed.

โ“

What Is This Demo Showing?

This is like a real online shopping cart! When you shop on Amazon, changing one thing (like quantity) automatically updates:

  • โ€ข Subtotal (price ร— quantity)
  • โ€ข Discounts (if you have a sale)
  • โ€ข Shipping costs (based on weight)
  • โ€ข Taxes (based on your location)
  • โ€ข Final total (everything combined)

๐ŸŽฏ Try it: Move any slider below and watch all the prices update instantly! SignalForge automatically knows what needs to recalculate.

๐Ÿ’ก

Why Is This Amazing?

Imagine coding this manually - you'd need to write code to recalculate everything whenever anything changes!

๐Ÿ˜ฐ Without SignalForge (Manual Way)

๐Ÿ“ You change the quantity

โš’๏ธ You manually recalculate subtotal

โš’๏ธ You manually recalculate discount

โš’๏ธ You manually recalculate shipping

โš’๏ธ You manually recalculate tax

โš’๏ธ You manually recalculate total

๐Ÿ˜ซ For 12 calculations: ~200 lines of code!

It's like doing your taxes by hand with a calculator! ๐Ÿง‘โ€๐Ÿ’ป

โœ… With SignalForge (Smart Way)

๐Ÿ“ You change the quantity

โœจ Everything updates automatically!

SignalForge tracks what depends on what, and only recalculates what changed.

const subtotal = createComputed(() => 
  price.get() * quantity.get()
);
// Done! Subtotal auto-updates! ๐ŸŽ‰

๐Ÿš€ For 12 calculations: ~50 lines of code!

Like having a personal accountant! ๐Ÿงพ

๐Ÿ”ง

How Does It Work? (3 Simple Steps!)

1

Create base signals (user inputs)

const price = createSignal(100);      // Base price
const quantity = createSignal(1);     // How many items
const discount = createSignal(10);    // Discount %

These are like the input fields in a form! ๐Ÿ“

2

Create computed values (automatic calculations)

const subtotal = createComputed(() => 
  price.get() * quantity.get()
);

const total = createComputed(() => 
  subtotal.get() - (subtotal.get() * discount.get() / 100)
);

These auto-update when inputs change! No manual work! โœจ

3

Use them in your UI

function Cart() {
  const totalValue = useSignalValue(total);
  return <div>Total: ${totalValue}</div>;
  // Updates automatically when anything changes! ๐ŸŽ‰
}

SignalForge handles all the math - you just display it! ๐Ÿ“Š

๐ŸŽฎ Play With The Shopping Cart!

๐Ÿ“Š How Your Total Is Calculated (Step-by-Step)

Base Price ร— Quantity

$100.00

Level 1: subtotal

- Discount (0%)

-$0.00

Level 1: discountAmount

After Discount

$100.00

Level 1: afterDiscount

+ Shipping

$5.00

Level 2: shippingCost

+ Tax (10%)

$10.50

Level 4: taxAmount

Final Total

$115.50

Level 5: finalTotal

๐ŸŒณ Dependency Tree

Level 0: Base Inputs

basePricequantitydiscountPercenttaxRateshippingWeightisPremiumMembercouponCode
โฌ‡๏ธ

Level 1: Basic Calculations

subtotaldiscountAmountafterDiscount
โฌ‡๏ธ

Level 2: Shipping Logic

shippingCost
โฌ‡๏ธ

Level 3: Coupon Logic

couponDiscountafterCoupon
โฌ‡๏ธ

Level 4: Tax Calculation

taxableAmounttaxAmount
โฌ‡๏ธ

Level 5: Final Result

finalTotaltotalSavings

๐Ÿ’€ The Redux Nightmare

SignalForge (12 lines)

// Define once, works everywhere
const subtotal = createComputed(() => 
  basePrice.get() * quantity.get()
);

const discountAmount = createComputed(() =>
  subtotal.get() * (discount.get() / 100)
);

const afterDiscount = createComputed(() =>
  subtotal.get() - discountAmount.get()
);

// ... 9 more like this
// Total: ~50 lines including all logic

Redux (100+ lines)

// Need reselect for memoization
import { createSelector } from 'reselect';

// Selector for each value
const selectBase = state => state.basePrice;
const selectQty = state => state.quantity;

// Memoized selector
const selectSubtotal = createSelector(
  [selectBase, selectQty],
  (base, qty) => base * qty
);

const selectDiscount = state => state.discount;
const selectDiscountAmount = createSelector(
  [selectSubtotal, selectDiscount],
  (sub, discount) => sub * (discount / 100)
);

// ... 50 more lines of selectors
// ... plus actions, reducers, types
// Total: ~200 lines for same logic

๐ŸŒ Real-World Use Cases

๐Ÿ’ผ Financial Calculators

Loan payments, investment returns, tax calculations with 20+ interdependent formulas. SignalForge handles the entire dependency tree automatically.

๐ŸŽฎ Game State

Character stats โ†’ equipment bonuses โ†’ skill modifiers โ†’ final damage. Change one item, everything updates instantly.

๐Ÿ“Š Analytics Dashboards

Raw data โ†’ filtered data โ†’ aggregations โ†’ visualizations. Filter changes propagate through entire pipeline in microseconds.

๐Ÿ›’ Complex Pricing

Volume discounts, member tiers, dynamic fees, currency conversion. This demo is a simplified real e-commerce scenario!