Skip to content

Commit

Permalink
Fixed infinite loop problem on delete by extracting method to keep DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasruebbelke-wf committed Feb 18, 2013
1 parent 7e6cd84 commit ba196ea
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions public/js/collab-board.js
Expand Up @@ -16,8 +16,8 @@ app.directive('stickyNote', function(socket) {
// Update if the same note
if(data.id == scope.note.id) {
element.animate({
left: data.x * 2,
top: data.y * 2
left: data.x,
top: data.y
});
}
});
Expand Down Expand Up @@ -94,7 +94,7 @@ app.controller('MainCtrl', function($scope, socket) {
});

socket.on('onNoteDeleted', function(data) {
$scope.deleteNote(data.id);
$scope.handleDeletedNoted(data.id);
});

// Outgoing
Expand All @@ -110,14 +110,21 @@ app.controller('MainCtrl', function($scope, socket) {
};

$scope.deleteNote = function(id) {
$scope.handleDeletedNoted(id);

socket.emit('deleteNote', {id: id});
};

$scope.handleDeletedNoted = function(id) {
console.log('HANDLE DELETE FIRED', id);

var oldNotes = $scope.notes,
newNotes = [];
newNotes = [];

angular.forEach(oldNotes, function(note) {
if(note.id !== id) newNotes.push(note);
});

$scope.notes = newNotes;
socket.emit('deleteNote', {id: id});
};
}
});

0 comments on commit ba196ea

Please sign in to comment.