@jede wrote:
We are struggling with how to transition away from observers in our Ember app.
For this case we have a 3rd party WebRTC library that starts when we call
startStream
. We cannot start the stream beforestatus
is'live'
andisConnected
istrue
After refactoring away observers this is what we came up with:_status: null, status: computed({ set(key, value) { const status = value.value this.set('_status', status) const isConnected = this.get('isConnected') this.handleStream(isConnected, status) return status }, get() { return this.get('_status') } }), _isConnected: false, isConnected: computed({ set(key, value) { this.set('_isConnected', value) const status = this.get('status') this.handleStream(value, status) return value }, get() { return this.get('_isConnected') } }), handleStream(isConnected, status) { if (!isConnected) return if (status === 'live') { this.startStream() } }
The old way:
handleStream: observer('liveStream.status', 'isConnected', function() { if (!this.get('isConnected')) return if (this.get('status') === 'live') { this.startStream() } })
The old way with an observer just looks so much shorter and easier to follow. Are we missing some better way of doing this?
Thanks!
Posts: 1
Participants: 1