Merge data coming from pusher instead of replacing everything
Pusher events do not always have the entire data for given object. That's why we need to merge incoming data instead of replacing everything. Current implementation of merge is just modified version of load function, so it will be best to either add it to Ember or make the implementation less dependent on internals.
This commit is contained in:
parent
39466a233f
commit
236ac25cbf
|
@ -1,9 +1,41 @@
|
|||
require 'store/rest_adapter'
|
||||
|
||||
DATA_PROXY =
|
||||
get: (name) ->
|
||||
@savedData[name]
|
||||
|
||||
Travis.Store = DS.Store.extend
|
||||
revision: 4
|
||||
adapter: Travis.RestAdapter.create()
|
||||
|
||||
merge: (type, id, hash) ->
|
||||
if hash == undefined
|
||||
hash = id
|
||||
primaryKey = type.proto().primaryKey
|
||||
Ember.assert("A data hash was loaded for a record of type " + type.toString() + " but no primary key '" + primaryKey + "' was provided.", hash[primaryKey])
|
||||
id = hash[primaryKey]
|
||||
|
||||
typeMap = @typeMapFor(type)
|
||||
dataCache = typeMap.cidToHash
|
||||
clientId = typeMap.idToCid[id]
|
||||
recordCache = @get('recordCache')
|
||||
|
||||
if clientId != undefined
|
||||
if data = dataCache[clientId]
|
||||
$.extend(data, hash)
|
||||
else
|
||||
dataCache[clientId] = hash
|
||||
|
||||
if record = recordCache[clientId]
|
||||
record.send('didChangeData')
|
||||
else
|
||||
clientId = @pushHash(hash, id, type)
|
||||
|
||||
DATA_PROXY.savedData = hash
|
||||
@updateRecordArrays(type, clientId, DATA_PROXY)
|
||||
|
||||
{ id: id, clientId: clientId }
|
||||
|
||||
receive: (name, data) ->
|
||||
mappings = @adapter.get('mappings')
|
||||
type = mappings[name]
|
||||
|
@ -18,10 +50,11 @@ Travis.Store = DS.Store.extend
|
|||
_loadOne: (store, type, json) ->
|
||||
root = type.singularName()
|
||||
@adapter.sideload(store, type, json, root)
|
||||
type.load(json[root])
|
||||
@merge(type, json[root])
|
||||
@_updateAssociations(type, root, json[root])
|
||||
|
||||
_loadMany: (store, type, json) ->
|
||||
console.log('loadMany')
|
||||
root = type.pluralName()
|
||||
@adapter.sideload(store, type, json, root)
|
||||
@loadMany(type, json[root])
|
||||
|
|
|
@ -97,6 +97,18 @@ describe 'events', ->
|
|||
row: 3
|
||||
item: { number: '1.4', repo: 'travis-ci/travis-core' }
|
||||
|
||||
it 'updates only keys that are available', ->
|
||||
Em.run ->
|
||||
Travis.app.receive 'job',
|
||||
job:
|
||||
id: 1
|
||||
build_id: 1
|
||||
|
||||
listsJob
|
||||
table: $('#jobs')
|
||||
row: 1
|
||||
item: { id: 1, number: '1.1', repo: 'travis-ci/travis-core', finishedAt: '3 minutes ago', duration: '30 sec', rvm: 'rbx' }
|
||||
|
||||
describe 'an event adding a worker', ->
|
||||
beforeEach ->
|
||||
app ''
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -430,7 +430,7 @@
|
|||
}
|
||||
});
|
||||
});
|
||||
return it('adds a job to the jobs queue', function() {
|
||||
it('adds a job to the jobs queue', function() {
|
||||
Em.run(function() {
|
||||
return Travis.app.receive('job', {
|
||||
job: {
|
||||
|
@ -450,6 +450,28 @@
|
|||
}
|
||||
});
|
||||
});
|
||||
return it('updates only keys that are available', function() {
|
||||
Em.run(function() {
|
||||
return Travis.app.receive('job', {
|
||||
job: {
|
||||
id: 1,
|
||||
build_id: 1
|
||||
}
|
||||
});
|
||||
});
|
||||
return listsJob({
|
||||
table: $('#jobs'),
|
||||
row: 1,
|
||||
item: {
|
||||
id: 1,
|
||||
number: '1.1',
|
||||
repo: 'travis-ci/travis-core',
|
||||
finishedAt: '3 minutes ago',
|
||||
duration: '30 sec',
|
||||
rvm: 'rbx'
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
return describe('an event adding a worker', function() {
|
||||
beforeEach(function() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user