Subs — Ember

// Unsubscribe (important!) this.eventBus.off('data-updated', this, this.handleUpdate);

Only use subscriptions when data enters your app . 3. Subscribing to External Data (Best Practice) Step 1: Create a service // app/services/price-feed.js import Service from '@ember/service'; import tracked from '@glimmer/tracking'; import action from '@ember/object'; export default class PriceFeedService extends Service @tracked currentPrice = null; @tracked isConnected = false; ember subs

#if this.priceFeed.isConnected Current price: this.priceFeed.currentPrice else Connecting... /if ✅ No manual observers – just tracked properties and lifecycle hooks. 4. Subscriptions with Ember Data (Live Queries) If your backend pushes changes via WebSockets, update the store directly: // Unsubscribe (important

⚠️ Use sparingly – overuse makes data flow hard to trace. | Pitfall | Fix | |---------|-----| | Forgetting to unsubscribe | Always call disconnect() or .off() in willDestroy | | Memory leaks | Check that references to components/services are cleared | | Stale data | Verify subscription updates tracked properties correctly | | Multiple subscriptions | Use a single service as the source of truth | /if ✅ No manual observers – just tracked