File tree 2 files changed +35
-0
lines changed
playgrounds/vue3/resources/js/Pages
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export class Request {
10
10
protected response ! : AxiosResponse
11
11
protected cancelToken ! : AbortController
12
12
protected requestParams : RequestParams
13
+ protected requestHasFinished = false
13
14
14
15
constructor (
15
16
params : ActiveVisit ,
@@ -72,6 +73,13 @@ export class Request {
72
73
}
73
74
74
75
protected fireFinishEvents ( ) : void {
76
+ if ( this . requestHasFinished ) {
77
+ // This could be called from multiple places, don't let it re-fire
78
+ return
79
+ }
80
+
81
+ this . requestHasFinished = true
82
+
75
83
fireFinishEvent ( this . requestParams . all ( ) )
76
84
this . requestParams . onFinish ( )
77
85
}
Original file line number Diff line number Diff line change @@ -78,6 +78,27 @@ const triggerCancel = () => {
78
78
)
79
79
}
80
80
81
+ const triggerCancelAfterFinish = () => {
82
+ let cancelToken
83
+
84
+ router .post (
85
+ ' /sleepy/1' ,
86
+ {},
87
+ {
88
+ onCancelToken : (token ) => {
89
+ console .log (' onCancelToken' )
90
+
91
+ cancelToken = token
92
+ },
93
+ onFinish : () => {
94
+ console .log (' onFinish' )
95
+ console .log (' CANCELLING!' )
96
+ cancelToken .cancel ()
97
+ },
98
+ },
99
+ )
100
+ }
101
+
81
102
watch (reloadCount , () => {
82
103
console .log (' watched reload count value' , reloadCount .value )
83
104
})
@@ -125,5 +146,11 @@ watch(reloadCount, () => {
125
146
<p >Trigger an automatic cancellation from the token.</p >
126
147
<button @click =" triggerCancel" class =" px-4 py-2 text-white bg-green-600 rounded" >Trigger Cancel</button >
127
148
</div >
149
+ <div class =" p-4 space-y-4 text-sm text-gray-500 border border-gray-300 rounded" >
150
+ <p >Trigger an automatic cancellation from the token after finishing request.</p >
151
+ <button @click =" triggerCancelAfterFinish" class =" px-4 py-2 text-white bg-green-600 rounded" >
152
+ Trigger Cancel After Finish
153
+ </button >
154
+ </div >
128
155
</div >
129
156
</template >
You can’t perform that action at this time.
0 commit comments