智慧水务管理系统 - 精河县供水工程综合管理平台

ResourceLoader.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import Check from "../Core/Check.js";
  2. import defined from "../Core/defined.js";
  3. import destroyObject from "../Core/destroyObject.js";
  4. import DeveloperError from "../Core/DeveloperError.js";
  5. import RuntimeError from "../Core/RuntimeError.js";
  6. /**
  7. * A cache resource.
  8. * <p>
  9. * This type describes an interface and is not intended to be instantiated directly.
  10. * </p>
  11. *
  12. * @see ResourceCache
  13. * @private
  14. */
  15. class ResourceLoader {
  16. /**
  17. * The cache key of the resource.
  18. *
  19. *
  20. * @type {string}
  21. * @readonly
  22. * @private
  23. */
  24. // eslint-disable-next-line getter-return
  25. get cacheKey() {
  26. DeveloperError.throwInstantiationError();
  27. }
  28. /**
  29. * Loads the resource.
  30. * @returns {Promise<ResourceLoader>} A promise which resolves to the loader when the resource loading is completed.
  31. * @private
  32. */
  33. load() {
  34. DeveloperError.throwInstantiationError();
  35. }
  36. /**
  37. * Unloads the resource.
  38. * @private
  39. */
  40. unload() {}
  41. /**
  42. * Processes the resource until it becomes ready.
  43. *
  44. * @param {FrameState} frameState The frame state.
  45. * @returns {boolean} true once all resourced are ready.
  46. * @private
  47. */
  48. process(frameState) {
  49. return false;
  50. }
  51. /**
  52. * Constructs a {@link RuntimeError} from an errorMessage and an error.
  53. *
  54. * @param {string} errorMessage The error message.
  55. * @param {Error} [error] The error.
  56. *
  57. * @returns {RuntimeError} The runtime error.
  58. * @private
  59. */
  60. getError(errorMessage, error) {
  61. //>>includeStart('debug', pragmas.debug);
  62. Check.typeOf.string("errorMessage", errorMessage);
  63. //>>includeEnd('debug');
  64. if (defined(error) && defined(error.message)) {
  65. errorMessage += `\n${error.message}`;
  66. }
  67. const runtimeError = new RuntimeError(errorMessage);
  68. if (defined(error)) {
  69. runtimeError.stack = `Original stack:\n${error.stack}\nHandler stack:\n${runtimeError.stack}`;
  70. }
  71. return runtimeError;
  72. }
  73. /**
  74. * Returns true if this object was destroyed; otherwise, false.
  75. * <br /><br />
  76. * If this object was destroyed, it should not be used; calling any function other than
  77. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
  78. *
  79. * @returns {boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
  80. *
  81. * @see ResourceLoader#destroy
  82. * @private
  83. */
  84. isDestroyed() {
  85. return false;
  86. }
  87. /**
  88. * Destroys the loaded resource.
  89. * <br /><br />
  90. * Once an object is destroyed, it should not be used; calling any function other than
  91. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
  92. * assign the return value (<code>undefined</code>) to the object as done in the example.
  93. *
  94. * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
  95. *
  96. * @example
  97. * resourceLoader = resourceLoader && resourceLoader.destroy();
  98. *
  99. * @see ResourceLoader#isDestroyed
  100. * @private
  101. */
  102. destroy() {
  103. this.unload();
  104. return destroyObject(this);
  105. }
  106. }
  107. export default ResourceLoader;