可以说,我们正在开发食谱应用程序,最初有2个请求。
/原料/
/食谱/
这些创建食谱和成分模型。
现在,食谱是由每种成分的成分和量制成的。
成分只有名称。
现在,使用模型和默认序列化和适配器很容易填充模型,如果我们确认 https://jsonapi.org/
当删除其中一种成分时,我们如何处理。在后端,我使用django if和成分被删除DB,还删除了与该成分有关的所有食谱。
但是在水疗应用程序上,让我们说我们运行
ingredient.deleteRecord();
ingredient.get('isDeleted'); // => true
ingredient.save();
还是
ingredient.destroyRecord();
如何更新食谱模型?那么,您是否手动执行服务器在客户端上的操作(并按Custome代码删除相关的配方)?还是您应该更新列表并重新填充它(更容易)。 需要对其进行更新
您可以在模型之间提供依赖关系,以便商店中的模型知道,当一个IT依赖项模型更改时, 注意将服务器和客户端保持同步的标准方法是什么。
这种东西的标准是什么。客户端应用应该再次重新获取所有数据,以确保服务器和水疗中心是insanc and uptotate。
谢谢
Lets say we are working on a recipe app and we have 2 get requests initially.
/ingredients/
/recipes/
These create the recipe and the ingredient model.
Now recipes are made of ingredients and amount of each ingredient.
And ingredients only have names.
Now populating the models are easy using the models and the default serializes and the adapters if we confirm to the https://jsonapi.org/
How do we handle when one of the ingredients is deleted. In the backend I use django if and ingredient is deleted DB also deletes all the recipes that have relation to the that ingredients.
But on the SPA application the let say we ran
ingredient.deleteRecord();
ingredient.get('isDeleted'); // => true
ingredient.save();
or
ingredient.destroyRecord();
How does the recipes model get updated ? So do you manually do what server does on the client(and delete related recipes by custome code)? Or should you just update the list and repopulate it(easier). And can you give dependencies between models so a model in the store would know that it need to be updated when one of it dependencies model is changed so it automatically make a get request and repopulate itself(are routes/models that clever?)
On that note what is the standard way of keeping server and client in sync.
What is the standard for this sort of stuff. Should client app re-get all that data again just to be sure that server and spa are insync and uptodate.
Thanks
发布评论
评论(1)
在删除成分的情况下,保存已经成功地在后端进行了,现在需要在UI真正同步之前从前端的许多食谱中删除成分删除商店:
In the scenario where an ingredient gets deleted, the save has gone through successfully on the backend and now needs that ingredient needs to be removed from many recipes on the frontend before your UI is truly in sync, I would suggest using this gist to push your delete properly into the store: https://gist.github.com/runspired/96618af26fb1c687a74eb30bf15e58b6