@v3ss0n wrote:
I am using a service at the backend that push data to store in realtime, via EventSource . While
store.createRecord().save()
is pushing into backend , it conflicts with client side store , and it cause duplicated records. As suggested by ember community at slack , i check the state of isSaving at records array , to make sure it won't conflict , and then push later when isSaving is false . So it pushes to client side store after data is saved properly. I use Ember.run.later with an interval to repeatedly check , but is there better way to do? like monitoring state change ofisSaving
?services's code (subscribe is eventsource subscriber)
start() { var unbind = subscribe('http://localhost:9999/updates', (data) => { var incoming = JSON.parse(data) var gid = incoming.id var curstore = this.get('store').peekAll('message') var checkSave = () => { if (this.get('store').peekAll('message').isAny("isSaving", true)) { Ember.run.later(() => { checkSave() }, 100) } else { this.get('store').pushPayload({ 'message': incoming }) } }; checkSave() }); },
Posts: 1
Participants: 1