Ecmascript 6 承诺和垃圾收集

Ecmascript 6 承诺和垃圾收集,ecmascript-6,redux,promise,react-redux,garbage-collection,Ecmascript 6,Redux,Promise,React Redux,Garbage Collection,我用react-redux设置了一个项目,我在我的动作创建者中使用redux-thunk进行抓取。下面是我的一个例子: export const doPostRequest=id=>{ 返回(调度,获取状态)=>{ const{id:initiailId}=getState().currentSelection 返回api.post(id).then(响应=>{ 如果(!isEqual(initialId,getState().currentSelection.id)){ 返回; } 派遣(其他

我用react-redux设置了一个项目,我在我的动作创建者中使用redux-thunk进行抓取。下面是我的一个例子:

export const doPostRequest=id=>{
返回(调度,获取状态)=>{
const{id:initiailId}=getState().currentSelection
返回api.post(id).then(响应=>{
如果(!isEqual(initialId,getState().currentSelection.id)){
返回;
}
派遣(其他行动(id))
返回承诺。解析(true)
})
.catch(err=>{})
}
}
正如您所看到的,如果在收到响应时我的状态的当前选择发生了更改,我想退出doPostRequest。否则,我将返回Promise.resolve(true),以便MyComponent中的onSubmit可以重置表单:

在组件(这是一个表单)中,onSubmit有以下内容:

class MyComponent extends React.PureComponent{

   onSubmit = id => {
       this.props.dispatch(doPostRequest(id))
          .then(shouldReset => shouldReset && resetForm())
   }

   render(){
       return <form onSubmit={this.onSubmit}>.....</form>
   }

}
类MyComponent扩展了React.PureComponent{ onSubmit=id=>{ 此.props.dispatch(doPostRequest(id)) 。然后(shouldReset=>shouldReset&&resetForm()) } render(){ 返回。。。。。 } } 在大多数情况下,当我真的不需要做任何其他事情,除了获取值,我不会在thunk上做承诺链,即使它返回一个承诺,但这里我需要在postrequest成功后执行resetForm

当涉及到GC时,这种实现是否足够好?垃圾是如何收集的?如果返回fetch().then()而不进一步链接它,是否有问题