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;
⚠️ 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 | ember subs
@cached get fullName() return $this.firstName $this.lastName ; connect() this
constructor() super(...arguments); this.priceFeed.connect(); this.socket.onmessage = (event) =>
@action updatePrice(data) this.currentPrice = data.price;
disconnect() this.socket?.close();
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;
⚠️ 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 |
@cached get fullName() return $this.firstName $this.lastName ;
constructor() super(...arguments); this.priceFeed.connect();
@action updatePrice(data) this.currentPrice = data.price;
disconnect() this.socket?.close();