Ember:欢迎处理闪存错误的建议 [英] Ember: Suggestions welcome for handling inFlight errors

查看:132
本文介绍了Ember:欢迎处理闪存错误的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Ember数据与REST适配器。我想确保在服务器响应缓慢的情况下,应用程序不会失败。



我已经模拟了在服务器端添加5秒钟的睡眠方法返回JSON响应。



如果您有一个带有SAVE按钮的表单,并且单击此按钮,而上一个保存仍然是进度,则会收到inFlight错误,整个Ember应用程序冻结(只有您可以做的事情是重新加载应用程序)。因此,您可以通过检查isSave状态轻松禁用保存按钮:

 < button {{action'save'}} {{bindAttr disabled =isSaving}}>保存< / button> 

现在看来,更改表单字段时,上一个保存仍然是进度,您会收到一个inFlight错误。这将表明我还需要禁用完整的表单。

 未捕获错误:尝试处理$ willSetProperty的
< App.Author:ember477:5203e34599808d1c6c000001>而在状态
rootState.loaded.updated.inFlight。使用{reference:[object Object],store:
< App.Store:ember541>,name:name}

是否有一个已知的良好做法来处理这些情况?我想阻止我需要为这些边缘案例添加大量逻辑(禁用按钮,设置字段readonly等)。

解决方案

可能不在您尝试做的范围内,但 Ember Persistence Foundation 旨在允许更新您的模型,而保存仍在飞行中。



它将模型迁移到EPF是相对微不足道的,但控制器代码中需要进行一些更改,请参见从Ember数据迁移


I use Ember data with the REST Adapter. I want to make sure that in case of slow server responses, the application does not fail.

I have simulated this bij adding at server side a sleep method of 5 seconds before returning the JSON response.

If you have a form with a SAVE button, and you click this button while a previous save is still is progress, you receive a inFlight error and the whole Ember app freezes (only thing you can do is reload app). So, you can easily disable the save button by checking the isSaving state:

<button {{action 'save'}} {{bindAttr disabled="isSaving"}}>Save</button>

Now it also seems that when changing a form field while a previous save is still is progress, you receive a inFlight error. This would thus indicate that I also need to disable the complete form.

Uncaught Error: Attempted to handle event `willSetProperty` on 
<App.Author:ember477:5203e34599808d1c6c000001> while in state 
rootState.loaded.updated.inFlight. Called with {reference: [object Object], store: 
<App.Store:ember541>, name: name} 

Is there a known good practice to handle these cases ... I want to prevent that I need to add a lot of logic (disable buttons, set fields readonly, etc.) for these edge cases.

解决方案

It may not be within the scope of what you are trying to do, but the Ember Persistence Foundation is designed to allow updating your models while a save is still in flight.

It is relatively trivial to migrate your models to EPF, but there are some changes required in the controller code, see "Migrating from Ember Data".

这篇关于Ember:欢迎处理闪存错误的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆