ResourceLoader.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. * @alias ResourceLoader
  13. * @constructor
  14. *
  15. * @see ResourceCache
  16. *
  17. * @private
  18. */
  19. export default function ResourceLoader() {}
  20. Object.defineProperties(ResourceLoader.prototype, {
  21. /**
  22. * A promise that resolves to the resource when the resource is ready.
  23. *
  24. * @memberof ResourceLoader.prototype
  25. *
  26. * @type {Promise.<ResourceLoader>}
  27. * @readonly
  28. * @private
  29. */
  30. promise: {
  31. // eslint-disable-next-line getter-return
  32. get: function () {
  33. DeveloperError.throwInstantiationError();
  34. },
  35. },
  36. /**
  37. * The cache key of the resource.
  38. *
  39. * @memberof ResourceLoader.prototype
  40. *
  41. * @type {String}
  42. * @readonly
  43. * @private
  44. */
  45. cacheKey: {
  46. // eslint-disable-next-line getter-return
  47. get: function () {
  48. DeveloperError.throwInstantiationError();
  49. },
  50. },
  51. });
  52. /**
  53. * Loads the resource.
  54. * @private
  55. */
  56. ResourceLoader.prototype.load = function () {
  57. DeveloperError.throwInstantiationError();
  58. };
  59. /**
  60. * Unloads the resource.
  61. * @private
  62. */
  63. ResourceLoader.prototype.unload = function () {};
  64. /**
  65. * Processes the resource until it becomes ready.
  66. *
  67. * @param {FrameState} frameState The frame state.
  68. * @private
  69. */
  70. ResourceLoader.prototype.process = function (frameState) {};
  71. /**
  72. * Constructs a {@link RuntimeError} from an errorMessage and an error.
  73. *
  74. * @param {String} errorMessage The error message.
  75. * @param {Error} [error] The error.
  76. *
  77. * @returns {RuntimeError} The runtime error.
  78. * @private
  79. */
  80. ResourceLoader.prototype.getError = function (errorMessage, error) {
  81. //>>includeStart('debug', pragmas.debug);
  82. Check.typeOf.string("errorMessage", errorMessage);
  83. //>>includeEnd('debug');
  84. if (defined(error)) {
  85. errorMessage += `\n${error.message}`;
  86. }
  87. return new RuntimeError(errorMessage);
  88. };
  89. /**
  90. * Returns true if this object was destroyed; otherwise, false.
  91. * <br /><br />
  92. * If this object was destroyed, it should not be used; calling any function other than
  93. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
  94. *
  95. * @returns {Boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
  96. *
  97. * @see ResourceLoader#destroy
  98. * @private
  99. */
  100. ResourceLoader.prototype.isDestroyed = function () {
  101. return false;
  102. };
  103. /**
  104. * Destroys the loaded resource.
  105. * <br /><br />
  106. * Once an object is destroyed, it should not be used; calling any function other than
  107. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
  108. * assign the return value (<code>undefined</code>) to the object as done in the example.
  109. *
  110. * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
  111. *
  112. * @example
  113. * resourceLoader = resourceLoader && resourceLoader.destroy();
  114. *
  115. * @see ResourceLoader#isDestroyed
  116. * @private
  117. */
  118. ResourceLoader.prototype.destroy = function () {
  119. this.unload();
  120. return destroyObject(this);
  121. };