Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangfisher committed Jan 22, 2024
1 parent 901439c commit 4a4440f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/store/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export type AsyncComputedObject<Value= any,ExtAttrs extends Dict = {}> ={
error? : any;
retry? : number // 重试次数,当执行重试操作时,会进行倒计时,每次重试-1,直到为0时停止重试
value : Value;
run : () => {}; // 重新执行任务
run : (options:{cancelable?:boolean}) => {}; // 重新执行任务
cancel : () => void; // 取消正在执行的任务
} & ExtAttrs

Expand Down Expand Up @@ -352,10 +352,21 @@ function createAsyncComputedObject(stateCtx:any,mutateId:string,valueObj:Partial
error: null,
progress: 0,
run: markRaw(
skipComputed(() => {
skipComputed((options:{cancelable?:boolean}) => {
const opts = Object.assign({cancelable:false},options)
const extraArgs:Dict = {}
if(opts.cancelable){
const abortController = new AbortController()
extraArgs.cancelSignal = abortController.signal
}
return stateCtx.runMutateTask({desc:mutateId,extraArgs:{a:1}});
})
)
),
cancel: markRaw(
skipComputed(() => {
return stateCtx.cancelMutateTask({desc:mutateId});
})
),
},valueObj)
}

Expand Down

0 comments on commit 4a4440f

Please sign in to comment.