在 Angular2 应用程序的前端存储对象实例数据是否可以接受?

Is it an acceptable practice to store object instance data on the front end in an Angular2 application?

在开发带有 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.

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

好的建议是只加载正确显示页面所需的数据。如果您需要显示数据列表,请尝试获取少量细节(可能是变化较小的细节)并且从该列表中选择一条记录后,您将进行 api 调用以完全加载与该数据相关的数据特定记录并可能填充详细视图。

如果您担心在 API 调用列表和将要编辑用户之间数据可能会发生变化,最好为此再发出一次 get 请求用户.

如果您不进行新的获取调用,数据确实会在列表获取调用和编辑之间发生变化,用户将编辑旧数据。