To remove to-do items from a shared list, we'll follow a similar pattern to adding items. In the
destroy function in
todo.coffee, we'll emit a
removeItem message to our socket to let the server know that a item should be removed, as shown in the following code snippet:
destroy: (elem) -> id = ($(elem).closest 'li').data('id') localStorage.removeItem id @socket.emit 'removeItem', id if @socket @displayItems()
Once again, we set up the server-side code to handle this message by removing the item from the shared list in memory, and then notify all clients connected to the list that the item has been removed:
io.sockets.on 'connection', (socket) => console.log("connected") socket.on 'joinList', (list) => console.log ...