import { PureComponent } from 'react'; import { cartAutomat } from '../automats/cartAutomat.js'; /** * CartManager — left column of the Partial Subscription example. * * Full subscriber to cartAutomat. * Allows adding/removing items (changing list length) AND modifying * existing item content (quantity, name, coupon) without changing list length. */ class CartManager extends PureComponent { _renderCount = 0; constructor(props) { super(props); this.state = cartAutomat.state; } componentDidMount() { this.unsubscribe = cartAutomat.subscribe(this); } componentWillUnmount() { if (this.unsubscribe) this.unsubscribe(); } handleAddItem = (name, price) => { cartAutomat.actions.addItem(name, price); }; handleRemoveItem = (id) => { cartAutomat.actions.removeItem(id); }; handleQuantityChange = (id, delta) => { cartAutomat.actions.updateQuantity(id, delta); }; handleCouponChange = (e) => { cartAutomat.actions.setCouponCode(e.target.value); }; handleReset = () => { cartAutomat.actions.resetCart(); }; render() { this._renderCount++; const { items, couponCode } = this.state; return (
cartAutomat.setState({`{ couponCode }`}). Notice how the badge on the right ignores this completely!