node.js - 在 Angular2 应用程序的前端存储对象实例数据是可以接受的做法吗?

标签 node.js angular restful-architecture

在使用 Node.js 后端开发 Angular2 应用程序时,最佳做法是仅存储对象的 id 并在每次需要对象的特定实例时进行 api 调用吗?

例如,如果我有这样的用户:

{public email: string,
 public password: string,
 public roles?: Role[],
 public firstName?: string,
 public lastName?: string,
 public _id?: string}

在我的前端,我对可以选择和编辑的用户列表进行了 API 调用。进行 API 调用来让特定用户进行编辑是否是最佳实践? 或者我应该进行 API 调用来获取用户列表并将其存储在前端的数组中,如下所示:

[{user}, {user}]

完成编辑后提交补丁请求?

我担心的是,在对列表进行 API 调用和编辑用户之间,服务器上的数据状态可能会发生变化。但是,存储项目并从内存中检索项目可能比调用 API 更快。

最佳答案

My concerns are that the data state on the server may change between when the API call for the list is made and when the user is edited. However it may be faster to store the items and retrieve it from memory than to make an API call.

在这种情况下,进行将返回 [user1, user2, ..] 列表的调用是一个坏主意,因为数据确实会很快变旧。

好的建议是加载正确显示页面所需的尽可能多的数据。如果您需要显示数据列表,请尝试获取一些详细信息(可能是变量较少的详细信息),一旦从此列表中选择一条记录,您就可以进行 api 调用来完全加载与特定记录相关的数据,也许填充详细 View 。

关于node.js - 在 Angular2 应用程序的前端存储对象实例数据是可以接受的做法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50279760/

相关文章:

node.js - 如何匹配 Thinky ORM 中的字段?

node.js - 无法将数据从 React Js 发布到 Node js

node.js - 如何判断请求是否来自本地机器的 Node 和/或 Express?

spring - 如何将带有 angular 2 前端(angular-cli 构建)的 spring-boot webapp 部署到 Tomcat?

json - 使用 REST API 删除本地/客户端对象的常用方法是什么?

node.js - 如何在 Gitlab 中为 nodejs 应用程序运行测试

javascript - $event 使用 PrimeNG 以 Angular 绑定(bind)

asp.net - Typescript 2.7 中的严格类初始化

java - 使用 Springfox 的 Swagger UI 中的超媒体链接

java - HttpUrlConnection PUT 方法不起作用