ajax-hook icon indicating copy to clipboard operation
ajax-hook copied to clipboard

fix: events handling

Open cyfung1031 opened this issue 1 year ago • 3 comments

getEventTarget(xhr)

  • only document.createElement('a') was used.
  • document.createDocumentFragment() would be a better way to create EventTarget since the creation of HTMLElement is slightly higher than DocumentFragment
  • document.createDocumentFragment() is well supported in ES5. (just Opera 10-12 is unknown)
  • No functional affect to the current script.

addEventListener and removeEventListener

  • removeEventListener was missing, but mentioned in index.d.ts
  • WeakMap is used for this particular usage.
  • WeakMap in very old browsers might be not supported, in that case, removeEventListener is ignored.
  • No functional affect to the current script.

Minor fix in event handler

  • ~changed event.type = args[0]; to event.type = e.type; to avoid memory leakage of array args.~ the type must be the same as the args[0]. assignment not required.

cyfung1031 avatar Aug 16 '23 13:08 cyfung1031

Combined Distribution Script ajaxhook.js for Testing (PR 119, 120, 121, 122) https://cdn.jsdelivr.net/gh/cyfung1031/ajax-hook@1ebe48e08108449669290a226e52fc6fbf7ec9ef/dist/ajaxhook.js

cyfung1031 avatar Aug 16 '23 15:08 cyfung1031

这次改动是要解决丢失 removeListener 的问题?

DAHUIAAAAA avatar Sep 02 '23 14:09 DAHUIAAAAA

这次改动是要解决丢失 removeListener 的问题?

之前只做了addEventListener,addEventListener跟removeEventListener是一對的 addEventListener裡面的把真正listen的function改了,一般removeEventListener是除掉不了

雖然很少機會會用removeEventListener,但你猜不到原本網站其他的XHR處理是怎樣,不理的話有機會報錯

cyfung1031 avatar Sep 02 '23 22:09 cyfung1031