Fix remaining ember-data and pusher updates issues
When records are updated by pusher events, we should not mark them as dirty - we don't modify them on client side anyway.
This commit is contained in:
parent
e96abff0e6
commit
46f7e6bba0
|
@ -52,7 +52,6 @@ Travis.Store = DS.Store.extend
|
||||||
!!@typeMapFor(type).idToCid[id]
|
!!@typeMapFor(type).idToCid[id]
|
||||||
|
|
||||||
receive: (event, data) ->
|
receive: (event, data) ->
|
||||||
#console.log event, data
|
|
||||||
[name, type] = event.split(':')
|
[name, type] = event.split(':')
|
||||||
|
|
||||||
mappings = @adapter.get('mappings')
|
mappings = @adapter.get('mappings')
|
||||||
|
|
|
@ -7,6 +7,22 @@ DS.JSONTransforms['object'] = {
|
||||||
}
|
}
|
||||||
|
|
||||||
Travis.Serializer = DS.RESTSerializer.extend
|
Travis.Serializer = DS.RESTSerializer.extend
|
||||||
|
# The next 3 methods specify the behavior of adding records to dirty sets
|
||||||
|
# (ie. which records will be treated as dirty on the next commit). We don't
|
||||||
|
# allow to change most of the records on the client, so for anything except
|
||||||
|
# the User, we ignore dirtyiness.
|
||||||
|
dirtyRecordsForAttributeChange: (dirtySet, record) ->
|
||||||
|
if record.constructor == Travis.User
|
||||||
|
@_super.apply this, arguments
|
||||||
|
|
||||||
|
dirtyRecordsForBelongsToChange: (dirtySet, record) ->
|
||||||
|
if record.constructor == Travis.User
|
||||||
|
@_super.apply this, arguments
|
||||||
|
|
||||||
|
dirtyRecordsForHasManyChange: (dirtySet, record) ->
|
||||||
|
if record.constructor == Travis.User
|
||||||
|
@_super.apply this, arguments
|
||||||
|
|
||||||
merge: (record, serialized) ->
|
merge: (record, serialized) ->
|
||||||
data = record.get('data')
|
data = record.get('data')
|
||||||
|
|
||||||
|
@ -42,9 +58,6 @@ Travis.Serializer = DS.RESTSerializer.extend
|
||||||
record.notifyPropertyChange(name)
|
record.notifyPropertyChange(name)
|
||||||
, this)
|
, this)
|
||||||
|
|
||||||
# TODO: add test that ensures that this line is called
|
|
||||||
# it should check if record goes into loaded.saved
|
|
||||||
# state after being in materializing
|
|
||||||
record.notifyPropertyChange('data')
|
record.notifyPropertyChange('data')
|
||||||
|
|
||||||
Travis.RestAdapter = DS.RESTAdapter.extend
|
Travis.RestAdapter = DS.RESTAdapter.extend
|
||||||
|
|
|
@ -18,7 +18,9 @@ describe 'Travis.Model - incomplete', ->
|
||||||
niceBar: DS.belongsTo('Travis.Bar')
|
niceBar: DS.belongsTo('Travis.Bar')
|
||||||
veryNiceBar: DS.belongsTo('Travis.Bar')
|
veryNiceBar: DS.belongsTo('Travis.Bar')
|
||||||
|
|
||||||
Travis.Bar = Travis.Model.extend()
|
Travis.Bar = Travis.Model.extend
|
||||||
|
name: DS.attr('string')
|
||||||
|
foos: DS.hasMany('Travis.Foo')
|
||||||
|
|
||||||
adapterClass = Travis.RestAdapter.extend()
|
adapterClass = Travis.RestAdapter.extend()
|
||||||
adapterClass.map 'Travis.Foo',
|
adapterClass.map 'Travis.Foo',
|
||||||
|
@ -33,6 +35,22 @@ describe 'Travis.Model - incomplete', ->
|
||||||
delete Travis.Bar
|
delete Travis.Bar
|
||||||
store.destroy()
|
store.destroy()
|
||||||
|
|
||||||
|
it 'allows to merge many times', ->
|
||||||
|
store.load(Travis.Bar, { id: '1', foo_ids: ['1', '2'] }, { id: '1' })
|
||||||
|
store.load(Travis.Foo, { id: '1', bar_id: '1' }, { id: '1' })
|
||||||
|
store.load(Travis.Foo, { id: '2', bar_id: '1' }, { id: '2' })
|
||||||
|
|
||||||
|
record = store.find(Travis.Bar, 1)
|
||||||
|
store.find(Travis.Foo, 1)
|
||||||
|
store.find(Travis.Foo, 2)
|
||||||
|
|
||||||
|
record.get('foos')
|
||||||
|
store.loadIncomplete(Travis.Bar, id: 1, name: 'foo')
|
||||||
|
store.loadIncomplete(Travis.Bar, id: 1, name: 'bar')
|
||||||
|
|
||||||
|
expect( record.get('foos.length') ).toEqual(2)
|
||||||
|
expect( record.get('name') ).toEqual('bar')
|
||||||
|
|
||||||
describe 'with incomplete record with loaded associations', ->
|
describe 'with incomplete record with loaded associations', ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
attrs = {
|
attrs = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user