O'Reilly logo

CoffeeScript Programming with jQuery, Rails, and Node.js by Michael Erasmus

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Removing to-do items from a shared list

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required