暂无描述

XMLHttpRequestEventTarget.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright 2016 wkh237@github. All rights reserved.
  2. // Use of this source code is governed by a MIT-style license that can be
  3. // found in the LICENSE file.
  4. import EventTarget from './EventTarget.js'
  5. import Log from '../utils/log.js'
  6. const log = new Log('XMLHttpRequestEventTarget')
  7. log.disable()
  8. // log.level(3)
  9. export default class XMLHttpRequestEventTarget extends EventTarget {
  10. _onabort : (e:Event) => void = () => {};
  11. _onerror : (e:Event) => void = () => {};
  12. _onload : (e:Event) => void = () => {};
  13. _onloadstart : (e:Event) => void = () => {};
  14. _onprogress : (e:Event) => void = () => {};
  15. _ontimeout : (e:Event) => void = () => {};
  16. _onloadend : (e:Event) => void = () => {};
  17. constructor() {
  18. super()
  19. log.info('constructor called')
  20. }
  21. dispatchEvent(event:string, e:Event) {
  22. log.debug('dispatch event', event, e)
  23. super.dispatchEvent(event, e)
  24. switch(event) {
  25. case 'abort' :
  26. this._onabort(e)
  27. break;
  28. case 'error' :
  29. this._onerror(e)
  30. break;
  31. case 'load' :
  32. this._onload(e)
  33. break;
  34. case 'loadstart' :
  35. this._onloadstart(e)
  36. break;
  37. case 'loadend' :
  38. this._onloadend(e)
  39. break;
  40. case 'progress' :
  41. this._onprogress(e)
  42. break;
  43. case 'timeout' :
  44. this._ontimeout(e)
  45. break;
  46. }
  47. }
  48. set onabort(fn:(e:Event) => void) {
  49. log.info('set onabort')
  50. this._onabort = fn
  51. }
  52. get onabort() {
  53. return this._onabort
  54. }
  55. set onerror(fn:(e:Event) => void) {
  56. log.info('set onerror')
  57. this._onerror = fn
  58. }
  59. get onerror() {
  60. return this._onerror
  61. }
  62. set onload(fn:(e:Event) => void) {
  63. log.info('set onload', fn)
  64. this._onload = fn
  65. }
  66. get onload() {
  67. return this._onload
  68. }
  69. set onloadstart(fn:(e:Event) => void) {
  70. log.info('set onloadstart')
  71. this._onloadstart = fn
  72. }
  73. get onloadstart() {
  74. return this._onloadstart
  75. }
  76. set onprogress(fn:(e:Event) => void) {
  77. log.info('set onprogress')
  78. this._onprogress = fn
  79. }
  80. get onprogress() {
  81. return this._onprogress
  82. }
  83. set ontimeout(fn:(e:Event) => void) {
  84. log.info('set ontimeout')
  85. this._ontimeout = fn
  86. }
  87. get ontimeout() {
  88. return this._ontimeout
  89. }
  90. set onloadend(fn:(e:Event) => void) {
  91. log.info('set onloadend')
  92. this._onloadend = fn
  93. }
  94. get onloadend() {
  95. return this._onloadend
  96. }
  97. }