@@ -3,6 +3,7 @@ export const cancelKey = "_ufs_cancel_";
33function _hook ( configs = [ ] ) {
44 const unsubFn = [ ] ;
55 for ( let { fn, arr } of configs ) {
6+ if ( typeof fn !== "function" || ! Array . isArray ( arr ) ) continue ;
67 let id = randId ( ) ;
78 arr . push ( { fn, id } ) ;
89 unsubFn . push ( ( ) => {
@@ -84,29 +85,26 @@ function initXhr() {
8485 window . XMLHttpRequest = new Proxy ( orig , {
8586 construct ( o , r ) {
8687 const instance = new o ( ...r ) ;
87-
8888 let p ;
8989
9090 const open = instance . open ;
9191 instance . open = function ( method , url , async , user , password ) {
92- this . _method = method ;
93- this . _url = url ;
94-
9592 p = { method, url, async, user, password } ;
9693 for ( let { fn } of onBeforeOpenXHRFn ) p = fn ?. ( p ) || p ;
9794 if ( p ?. [ cancelKey ] ) return ;
9895
99- return open . apply ( this , [ p . mr ] ) ;
96+ return open . apply ( this , [ p . method , p . url , p . async , p . user , p . password ] ) ;
10097 } ;
10198
10299 const send = instance . send ;
103- instance . send = function ( data ) {
104- for ( let { fn } of onBeforeSendXHRFn ) data = fn ?. ( p , data ) || data ;
105- if ( data ?. [ cancelKey ] ) return ;
100+ instance . send = function ( dataSend ) {
101+ for ( let { fn } of onBeforeSendXHRFn )
102+ dataSend = fn ?. ( p , dataSend ) || dataSend ;
103+ if ( dataSend ?. [ cancelKey ] ) return ;
106104
107105 instance . addEventListener ( "load" , function ( ) {
108106 for ( let { fn } of onAfterSendXHRFn )
109- fn ?. ( p , data , instance . responseText ) ;
107+ fn ?. ( p , dataSend , instance . response ) ;
110108 } ) ;
111109
112110 return send . apply ( this , arguments ) ;
0 commit comments