ember.js - DS.defaultStore.load(App.foo, payload) only works first time with DS.RESTAdapter -
update: this non-issue (see below)
so wrote jsfiddle show bad behavior except fiddle works! , real code doesn't. difference using restadapter in real code data pulled server instead of fixtures.
in jsfiddle: first click 'simulate 1st manual load', click 2nd button see work (i.e. loading new or updated data store multiple times in row)
http://jsfiddle.net/iceking1624/nzz42/4/
the issue
i sending updated information on websockets ember app. set listener trigger function on correct controller , able update records first time. successive attempts not update store , wonder if has state of store? unsure of how handle if case.
this code updates or adds records come on websockets:
app.sessioncontroller = ember.objectcontroller.extend({ updatereceived: function(data) { console.log(data); ds.defaultstore.load(app.choice, data.choice); ds.defaultstore.load(app.question, data.question); } }); notice console.log(data) part. every single time send updated data via websockets, updatereceived called , correct data logged every time, ds.defaultstore.load(...) works first time.
the reason update both app.question & app.choice because have relationship:
app.question = ds.model.extend({ "choices" : ds.hasmany('app.choice') }); app.choice = ds.model.extend({ "question" : ds.belongsto('app.question') }); i don't think code below relevant issue in case interested, how listen events on websockets (using socket.io):
app.sessionroute = ember.route.extend({ enter: function() { this.socket = io.connect('http://10.0.1.4') }, setupcontroller: function(controller, model) { var self = this; this.socket.on('update', function(data) { self.controller.send('updatereceived', data) }) } }); are there suggestions how can continuously load new or updated records directly store (and not once)?
update:
the code indeed correct. new data loading store fine wasn't re-rending view correctly when new/updated information loaded ds.defaultstore
i don't want delete question since others may find information in useful vote how like. i'm sorry didn't catch before writing question.
Comments
Post a Comment