I thought about getting rid of all client-side Ajax calls (jQuery) and instead use a permanent socket connection (Socket.IO).
Therefore I would use event listeners/emitters client-side and server-side.
Ex. a click event is triggered by user in the browser, client-side emitter pushes the event through socket connection to server. Server-side listener reacts on incoming event, and pushes “done” event back to client. Client’s listener reacts on incoming event by fading in DIV element.
Does that make sense at all?
Pros & cons?
Sending one way messages and invoking callbacks to them can get very messy.
$.get('/api', sendData, returnFunction);is cleaner thansocket.emit('sendApi', sendData);socket.on('receiveApi', returnFunction);Which is why dnode and nowjs were built on top of socket.io to make things manageable. Still event driven but without giving up callbacks.