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

Node.js相关问答推荐

Express 4.18正文解析

(0,core_1.default)不是使用@middy/core的lambda处理程序上的函数

为什么我收到此错误:MissingSchemaError:架构尚未为模型&业务&注册

编写动态创建的 YAML - 为生态系统创建 Docker compose 文件(使用 js-yaml)

我的 React + Express 应用程序不断向我的数组添加一个空对象

Express Web 服务器部署到 prod 但 GET 返回超时错误

如何找到特定文档并更新数组中特定键的值?

带有事件网格的 Azure 函数在没有 ngrok 的情况下在本地运行

如何在 Nest.js 中使用查询参数?

使用 Webpack 和 font-face 加载字体

如何在 Joi 字符串验证中使用枚举值

Node.js `--nolazy` 标志是什么意思?

mongo 可以 upsert 数组数据吗?

安装 node 包时可以使用自定义目录名称而不是node_modules吗?

如何从 Node.js 中的 URL 获取

Node.js 与 .net 中的异步/等待

NPM:为什么要安装这个包?

什么时候应该将函数存储到变量中?

CORS 错误:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段授权

Sequelize:如何从现有数据库中导入定义