Skip to content

Commit dc2a60f

Browse files
committed
pass new item into callback on socket update
1 parent 6cfd6b9 commit dc2a60f

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

app/templates/client/components/socket(socketio)/socket.service(coffee).coffee

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,28 @@ angular.module('<%= scriptAppName %>').factory 'socket', (socketFactory) ->
3737
###
3838
Syncs item creation/updates on 'model:save'
3939
###
40-
socket.on modelName + ":save", (newItem) ->
40+
socket.on modelName + ":save", (item) ->
4141
oldItem = _.find(array,
42-
_id: newItem._id
42+
_id: item._id
4343
)
4444
index = array.indexOf(oldItem)
4545

4646
# replace oldItem if it exists
47-
# otherwise just add newItem to the collection
47+
# otherwise just add item to the collection
4848
if oldItem
49-
array.splice index, 1, newItem
49+
array.splice index, 1, item
5050
else
51-
array.push newItem
52-
cb array
51+
array.push item
52+
cb item, array
5353

5454
###
5555
Syncs removed items on 'model:remove'
5656
###
57-
socket.on modelName + ":remove", (newItem) ->
57+
socket.on modelName + ":remove", (item) ->
5858
_.remove array,
59-
_id: newItem._id
59+
_id: item._id
6060

61-
cb array
61+
cb item, array
6262

6363
###
6464
Removes listeners for a models updates on the socket

app/templates/client/components/socket(socketio)/socket.service.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,27 @@ angular.module('<%= scriptAppName %>')
5050
/**
5151
* Syncs item creation/updates on 'model:save'
5252
*/
53-
socket.on(modelName + ':save', function (newItem) {
54-
var oldItem = _.find(array, {_id: newItem._id});
53+
socket.on(modelName + ':save', function (item) {
54+
var oldItem = _.find(array, {_id: item._id});
5555
var index = array.indexOf(oldItem);
5656

5757
// replace oldItem if it exists
58-
// otherwise just add newItem to the collection
58+
// otherwise just add item to the collection
5959
if (oldItem) {
60-
array.splice(index, 1, newItem);
60+
array.splice(index, 1, item);
6161
} else {
62-
array.push(newItem);
62+
array.push(item);
6363
}
6464

65-
cb(array);
65+
cb(item, array);
6666
});
6767

6868
/**
6969
* Syncs removed items on 'model:remove'
7070
*/
71-
socket.on(modelName + ':remove', function (newItem) {
72-
_.remove(array, {_id: newItem._id});
73-
cb(array);
71+
socket.on(modelName + ':remove', function (item) {
72+
_.remove(array, {_id: item._id});
73+
cb(item, array);
7474
});
7575
},
7676

0 commit comments

Comments
 (0)