Ember Subs May 2026

disconnect() this.socket?.close();

@action updatePrice(data) this.currentPrice = data.price; ember subs

⚠️ 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 | disconnect() this

// Publish this.eventBus.trigger('data-updated', some: 'data' ); @action updatePrice(data) this.currentPrice = data.price

connect() this.socket = new WebSocket('wss://example.com/prices'); this.socket.onmessage = (event) => this.updatePrice(JSON.parse(event.data)); ; this.socket.onopen = () => this.isConnected = true;

// app/services/event-bus.js import Service from '@ember/service'; import Evented from '@ember/object/evented'; export default class EventBusService extends Service.extend(Evented) {}