মূল কনটেন্টে যান
🐹
emberjs learning
Reactivity•দিন ০০৫/৬৫

Build Reactive Chains with Dependent Getters

এই দিনের কাজ · মোট ১০′০/১ (০%)
  • Build Reactive Chains with Dependent Getters — নিচের Incorrect কোড পড়ে, না দেখে ঠিক সংস্করণটা লিখুন; তারপর "কেন" ইংরেজিতে ২–৩ বাক্যে জোরে বলুন, আর খাতায় এক লাইন: নিজের কাজে এটা কোথায় দেখেছেন

    Incorrect (imperative updates):

    // app/components/shopping-cart.gjs
    import Component from '@glimmer/component';
    import { tracked } from '@glimmer/tracking';
    import { action } from '@ember/object';
    
    class ShoppingCart extends Component {
      @tracked items = [];
      @tracked subtotal = 0;
      @tracked tax = 0;
      @tracked shipping = 0;
      @tracked total = 0;
    
      @action
      addItem(item) {
        this.items = [...this.items, item];
        this.recalculate();
      }
    
      @action
      removeItem(index) {
        this.items = this.items.filter((_, i) => i !== index);
        this.recalculate();
      }
    
      recalculate() {
        this.subtotal = this.items.reduce((sum, item) => sum + item.price, 0);
        this.tax = this.subtotal * 0.08;
        this.shipping = this.subtotal > 50 ? 0 : 5.99;
        this.total = this.subtotal + this.tax + this.shipping;
      }
    
      <template>
        <div class="cart">
          <div>Subtotal: ${{this.subtotal}}</div>
          <div>Tax: ${{this.tax}}</div>
          <div>Shipping: ${{this.shipping}}</div>
          <div>Total: ${{this.total}}</div>
        </div>
      </template>
    }
    
    ১০′🔁 ঝালাই হবেimpact · HIGHCorrect: আগে নিজে লিখুন
দিন শেষে — নিজেকে যাচাই
না দেখে ঠিকটা লেখা, আর "কেন" ইংরেজিতে জোরে বলা হয়েছে?

উত্তরের আগে উপরের কাজ না দেখে মনে করুন এই দিনে কী কী করেছেন। 🧠 Test yourself