First, we'll handle adding new items on the server. The best place to handle this would be in the existing
create function for creating to-do items. Instead of just adding them to
localStorage, we'll also emit a message to the server telling it that a new to-do item has been created, and pass it as a parameter. Modify the
create function to look like the following code:
create: (e) -> val = $.trim @$input.val() return unless e.which == 13 and val randomId = Math.floor Math.random()*999999 newItem = id: randomId title: val completed: false localStorage.setObj randomId, newItem @socket.emit 'newItem', newItem if @socket @$input.val '' @displayItems()
We need to handle the
newItem message on the server. We'll ...