🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

webgltexture-loader

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webgltexture-loader - npm Package Compare versions

Comparing version

to
0.12.0-minor.adc60f91

18

lib/globalRegistry.js

@@ -1,19 +0,9 @@

"use strict";
import LoadersRegistry from "./LoadersRegistry";
Object.defineProperty(exports, "__esModule", {
value: true
});
const root = typeof window === "undefined" ? global : window;
const key = "__webglTextureLoader_registry";
var _LoadersRegistry = require("./LoadersRegistry");
var _LoadersRegistry2 = _interopRequireDefault(_LoadersRegistry);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var root = typeof window === "undefined" ? global : window;
var key = "__webglTextureLoader_registry";
// This is a convenient loader registry that store all imported registry
// it needs to be in global state so it does not get lost across potential many lib instances
exports.default = root[key] || (root[key] = new _LoadersRegistry2.default());
export default root[key] || (root[key] = new LoadersRegistry());
//# sourceMappingURL=globalRegistry.js.map

@@ -1,16 +0,7 @@

"use strict";
import globalRegistry from "./globalRegistry";
import LoadersRegistry from "./LoadersRegistry";
var _globalRegistry = require("./globalRegistry");
var _globalRegistry2 = _interopRequireDefault(_globalRegistry);
var _LoadersRegistry = require("./LoadersRegistry");
var _LoadersRegistry2 = _interopRequireDefault(_LoadersRegistry);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
test("globalRegistry is available", function () {
expect(_globalRegistry2.default).toBeInstanceOf(_LoadersRegistry2.default);
test("globalRegistry is available", () => {
expect(globalRegistry).toBeInstanceOf(LoadersRegistry);
});
//# sourceMappingURL=globalRegistry.test.js.map

@@ -1,40 +0,9 @@

"use strict";
import WebGLTextureLoader from "./WebGLTextureLoader";
import WebGLTextureLoaderAsyncHashCache from "./WebGLTextureLoaderAsyncHashCache";
import WebGLTextureLoaderSyncHashCache from "./WebGLTextureLoaderSyncHashCache";
import LoadersRegistry from "./LoadersRegistry";
import LoaderResolver from "./LoaderResolver";
import globalRegistry from "./globalRegistry";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WebGLTextureLoaderSyncHashCache = exports.WebGLTextureLoaderAsyncHashCache = exports.WebGLTextureLoader = exports.LoaderResolver = exports.LoadersRegistry = exports.globalRegistry = undefined;
var _WebGLTextureLoader = require("./WebGLTextureLoader");
var _WebGLTextureLoader2 = _interopRequireDefault(_WebGLTextureLoader);
var _WebGLTextureLoaderAsyncHashCache = require("./WebGLTextureLoaderAsyncHashCache");
var _WebGLTextureLoaderAsyncHashCache2 = _interopRequireDefault(_WebGLTextureLoaderAsyncHashCache);
var _WebGLTextureLoaderSyncHashCache = require("./WebGLTextureLoaderSyncHashCache");
var _WebGLTextureLoaderSyncHashCache2 = _interopRequireDefault(_WebGLTextureLoaderSyncHashCache);
var _LoadersRegistry = require("./LoadersRegistry");
var _LoadersRegistry2 = _interopRequireDefault(_LoadersRegistry);
var _LoaderResolver = require("./LoaderResolver");
var _LoaderResolver2 = _interopRequireDefault(_LoaderResolver);
var _globalRegistry = require("./globalRegistry");
var _globalRegistry2 = _interopRequireDefault(_globalRegistry);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.globalRegistry = _globalRegistry2.default;
exports.LoadersRegistry = _LoadersRegistry2.default;
exports.LoaderResolver = _LoaderResolver2.default;
exports.WebGLTextureLoader = _WebGLTextureLoader2.default;
exports.WebGLTextureLoaderAsyncHashCache = _WebGLTextureLoaderAsyncHashCache2.default;
exports.WebGLTextureLoaderSyncHashCache = _WebGLTextureLoaderSyncHashCache2.default;
export { globalRegistry, LoadersRegistry, LoaderResolver, WebGLTextureLoader, WebGLTextureLoaderAsyncHashCache, WebGLTextureLoaderSyncHashCache };
//# sourceMappingURL=index.js.map

@@ -1,48 +0,17 @@

"use strict";
import globalRegistry from "./globalRegistry";
Object.defineProperty(exports, "__esModule", {
value: true
});
export default class LoaderResolver {
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
constructor(gl, registry = globalRegistry) {
this.loaders = registry.get().map(L => new L(gl));
}
var _globalRegistry = require("./globalRegistry");
dispose() {
this.loaders.forEach(l => l.dispose());
}
var _globalRegistry2 = _interopRequireDefault(_globalRegistry);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var LoaderResolver = function () {
function LoaderResolver(gl) {
var registry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _globalRegistry2.default;
_classCallCheck(this, LoaderResolver);
this.loaders = registry.get().map(function (L) {
return new L(gl);
});
resolve(input) {
return this.loaders.find(loader => loader.canLoad(input));
}
_createClass(LoaderResolver, [{
key: "dispose",
value: function dispose() {
this.loaders.forEach(function (l) {
return l.dispose();
});
}
}, {
key: "resolve",
value: function resolve(input) {
return this.loaders.find(function (loader) {
return loader.canLoad(input);
});
}
}]);
return LoaderResolver;
}();
exports.default = LoaderResolver;
}
//# sourceMappingURL=LoaderResolver.js.map

@@ -1,28 +0,8 @@

"use strict";
import LoaderResolver from "./LoaderResolver";
import LoadersRegistry from "./LoadersRegistry";
import WebGLTextureLoaderSyncHashCache from "./WebGLTextureLoaderSyncHashCache";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _LoaderResolver = require("./LoaderResolver");
var _LoaderResolver2 = _interopRequireDefault(_LoaderResolver);
var _LoadersRegistry = require("./LoadersRegistry");
var _LoadersRegistry2 = _interopRequireDefault(_LoadersRegistry);
var _WebGLTextureLoaderSyncHashCache = require("./WebGLTextureLoaderSyncHashCache");
var _WebGLTextureLoaderSyncHashCache2 = _interopRequireDefault(_WebGLTextureLoaderSyncHashCache);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
test("an empty LoaderResolver resolves nothing", function () {
var gl = {};
var resolver = new _LoaderResolver2.default(gl);
test("an empty LoaderResolver resolves nothing", () => {
const gl = {};
const resolver = new LoaderResolver(gl);
expect(resolver.resolve(null)).toBeUndefined();

@@ -34,42 +14,23 @@ expect(resolver.resolve(42)).toBeUndefined();

test("LoaderResolver works with one loader", function () {
var gl = {
deleteTexture: function deleteTexture() {}
test("LoaderResolver works with one loader", () => {
const gl = {
deleteTexture: () => {}
};
var registry = new _LoadersRegistry2.default();
var FakeLoader = function (_WebGLTextureLoaderSy) {
_inherits(FakeLoader, _WebGLTextureLoaderSy);
function FakeLoader() {
_classCallCheck(this, FakeLoader);
return _possibleConstructorReturn(this, (FakeLoader.__proto__ || Object.getPrototypeOf(FakeLoader)).apply(this, arguments));
const registry = new LoadersRegistry();
class FakeLoader extends WebGLTextureLoaderSyncHashCache {
canLoad(input) {
return typeof input === "number";
}
_createClass(FakeLoader, [{
key: "canLoad",
value: function canLoad(input) {
return typeof input === "number";
}
}, {
key: "inputHash",
value: function inputHash(input) {
return input;
}
}, {
key: "getNoCache",
value: function getNoCache(input) {
return { texture: { id: input }, width: 2, height: 2 };
}
}]);
return FakeLoader;
}(_WebGLTextureLoaderSyncHashCache2.default);
inputHash(input) {
return input;
}
getNoCache(input) {
return { texture: { id: input }, width: 2, height: 2 };
}
}
registry.add(FakeLoader);
var resolver = new _LoaderResolver2.default(gl, registry);
const resolver = new LoaderResolver(gl, registry);
expect(resolver.resolve(null)).toBeUndefined();
expect(resolver.resolve("foo")).toBeUndefined();
var loader = resolver.resolve(42);
const loader = resolver.resolve(42);
expect(loader).toBeDefined();

@@ -76,0 +37,0 @@ expect(loader).toBeInstanceOf(FakeLoader);

@@ -1,11 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**

@@ -15,51 +7,32 @@ * LoadersRegistry

*/
var LoadersRegistry = function () {
function LoadersRegistry() {
_classCallCheck(this, LoadersRegistry);
export default class LoadersRegistry {
constructor() {
this._loaders = [];
}
_createClass(LoadersRegistry, [{
key: "add",
/**
* Add a TextureLoader class to extend texture format support.
*/
add(loader) {
this._loaders.push(loader);
this._loaders.sort((a, b) => (typeof b.priority === "number" ? b.priority : 0) - (typeof a.priority === "number" ? a.priority : 0));
}
/**
* Add a TextureLoader class to extend texture format support.
*/
value: function add(loader) {
this._loaders.push(loader);
this._loaders.sort(function (a, b) {
return (typeof b.priority === "number" ? b.priority : 0) - (typeof a.priority === "number" ? a.priority : 0);
});
/**
* Remove a previously added WebGLTextureLoader class.
*/
remove(loader) {
const i = this._loaders.indexOf(loader);
if (i !== -1) {
this._loaders.splice(i, 1);
}
}
/**
* Remove a previously added WebGLTextureLoader class.
*/
}, {
key: "remove",
value: function remove(loader) {
var i = this._loaders.indexOf(loader);
if (i !== -1) {
this._loaders.splice(i, 1);
}
}
/**
* List the loaders ordered by most priority first
*/
}, {
key: "get",
value: function get() {
return this._loaders;
}
}]);
return LoadersRegistry;
}();
exports.default = LoadersRegistry;
/**
* List the loaders ordered by most priority first
*/
get() {
return this._loaders;
}
}
//# sourceMappingURL=LoadersRegistry.js.map

@@ -1,15 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* a WebGLTextureLoader handle the loading of WebGLTexture for a given input object.
*/
var WebGLTextureLoader = function () {
export default class WebGLTextureLoader {

@@ -19,5 +11,3 @@ /**

*/
function WebGLTextureLoader(gl) {
_classCallCheck(this, WebGLTextureLoader);
constructor(gl) {
this.gl = gl;

@@ -52,19 +42,10 @@ }

_createClass(WebGLTextureLoader, [{
key: "update",
/**
* sync the webgl texture with a loaded input. for instance for <video>/<canvas> elements this needs to be called recurrently (like in a requestAnimationFrame loop) to get the texture updated.
* update should only get called IF get(input) was returning a result.
*/
value: function update(input) {
// Default implementation don't do anything which works for all static content like an image
}
}]);
return WebGLTextureLoader;
}();
exports.default = WebGLTextureLoader;
/**
* sync the webgl texture with a loaded input. for instance for <video>/<canvas> elements this needs to be called recurrently (like in a requestAnimationFrame loop) to get the texture updated.
* update should only get called IF get(input) was returning a result.
*/
update(input) {
// Default implementation don't do anything which works for all static content like an image
}
}
//# sourceMappingURL=WebGLTextureLoader.js.map

@@ -1,117 +0,69 @@

"use strict";
import WebGLTextureLoader from "./WebGLTextureLoader";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
const neverEnding = new Promise(() => {});
var _WebGLTextureLoader2 = require("./WebGLTextureLoader");
var _WebGLTextureLoader3 = _interopRequireDefault(_WebGLTextureLoader2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var neverEnding = new Promise(function () {});
/**
* A cache implementation of WebGLTextureLoader with a input hash function
*/
class WebGLTextureLoaderAsyncHashCache extends WebGLTextureLoader {
constructor(...args) {
var _temp;
var WebGLTextureLoaderAsyncHashCache = function (_WebGLTextureLoader) {
_inherits(WebGLTextureLoaderAsyncHashCache, _WebGLTextureLoader);
return _temp = super(...args), this.disposes = new Map(), this.inputs = new Map(), this.promises = new Map(), this.results = new Map(), this._disposed = false, _temp;
}
// An async load function that does not cache (WebGLTextureLoaderAsyncHashCache do the caching with inputHash). it also should return a dispose function to cancel a pending load
function WebGLTextureLoaderAsyncHashCache() {
var _ref;
var _temp, _this, _ret;
dispose() {
const { gl, promises, results, inputs, disposes } = this;
disposes.forEach(d => d());
results.forEach(result => {
this.disposeTexture(result.texture);
});
promises.clear();
results.clear();
inputs.clear();
disposes.clear();
this._disposed = true;
}
_classCallCheck(this, WebGLTextureLoaderAsyncHashCache);
disposeTexture(texture) {
this.gl.deleteTexture(texture);
}
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
load(input) {
const hash = this.inputHash(input);
const maybePromise = this.promises.get(hash);
if (maybePromise) return maybePromise;
const d = this.loadNoCache(input);
this.disposes.set(hash, d.dispose);
const promise = d.promise.then(result => {
if (!this.promises.has(hash)) {
return neverEnding;
}
this.disposes.delete(hash);
this.results.set(hash, result);
return result;
});
this.promises.set(hash, promise);
return promise;
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = WebGLTextureLoaderAsyncHashCache.__proto__ || Object.getPrototypeOf(WebGLTextureLoaderAsyncHashCache)).call.apply(_ref, [this].concat(args))), _this), _this.disposes = new Map(), _this.inputs = new Map(), _this.promises = new Map(), _this.results = new Map(), _this._disposed = false, _temp), _possibleConstructorReturn(_this, _ret);
get(input) {
return this.results.get(this.inputHash(input));
}
// An async load function that does not cache (WebGLTextureLoaderAsyncHashCache do the caching with inputHash). it also should return a dispose function to cancel a pending load
_createClass(WebGLTextureLoaderAsyncHashCache, [{
key: "dispose",
value: function dispose() {
var _this2 = this;
var gl = this.gl,
promises = this.promises,
results = this.results,
inputs = this.inputs,
disposes = this.disposes;
disposes.forEach(function (d) {
return d();
});
results.forEach(function (result) {
_this2.disposeTexture(result.texture);
});
promises.clear();
results.clear();
inputs.clear();
disposes.clear();
this._disposed = true;
cancelLoad(input) {
const hash = this.inputHash(input);
this.promises.delete(hash);
const dispose = this.disposes.get(hash);
if (dispose) {
dispose();
this.disposes.delete(hash);
}
}, {
key: "disposeTexture",
value: function disposeTexture(texture) {
this.gl.deleteTexture(texture);
}
}, {
key: "load",
value: function load(input) {
var _this3 = this;
}
}
var hash = this.inputHash(input);
var maybePromise = this.promises.get(hash);
if (maybePromise) return maybePromise;
var d = this.loadNoCache(input);
this.disposes.set(hash, d.dispose);
var promise = d.promise.then(function (result) {
if (!_this3.promises.has(hash)) {
return neverEnding;
}
_this3.disposes.delete(hash);
_this3.results.set(hash, result);
return result;
});
this.promises.set(hash, promise);
return promise;
}
}, {
key: "get",
value: function get(input) {
return this.results.get(this.inputHash(input));
}
}, {
key: "cancelLoad",
value: function cancelLoad(input) {
var hash = this.inputHash(input);
this.promises.delete(hash);
var dispose = this.disposes.get(hash);
if (dispose) {
dispose();
this.disposes.delete(hash);
}
}
}]);
return WebGLTextureLoaderAsyncHashCache;
}(_WebGLTextureLoader3.default);
exports.default = WebGLTextureLoaderAsyncHashCache;
export default WebGLTextureLoaderAsyncHashCache;
//# sourceMappingURL=WebGLTextureLoaderAsyncHashCache.js.map

@@ -1,101 +0,46 @@

"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _WebGLTextureLoaderAsyncHashCache = require("./WebGLTextureLoaderAsyncHashCache");
var _WebGLTextureLoaderAsyncHashCache2 = _interopRequireDefault(_WebGLTextureLoaderAsyncHashCache);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
test("WebGLTextureLoaderAsyncHashCache simple usage", _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
var gl, FakeLoader, loader, res;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
gl = {
deleteTexture: function deleteTexture() {}
};
import WebGLTextureLoaderAsyncHashCache from "./WebGLTextureLoaderAsyncHashCache";
FakeLoader = function (_WebGLTextureLoaderAs) {
_inherits(FakeLoader, _WebGLTextureLoaderAs);
function FakeLoader() {
_classCallCheck(this, FakeLoader);
return _possibleConstructorReturn(this, (FakeLoader.__proto__ || Object.getPrototypeOf(FakeLoader)).apply(this, arguments));
}
_createClass(FakeLoader, [{
key: "canLoad",
value: function canLoad(input) {
return typeof input === "number";
}
}, {
key: "inputHash",
value: function inputHash(input) {
return input;
}
}, {
key: "loadNoCache",
value: function loadNoCache(input) {
return {
promise: Promise.resolve({
texture: { id: input },
width: 2,
height: 2
}),
dispose: function dispose() {}
};
}
}]);
return FakeLoader;
}(_WebGLTextureLoaderAsyncHashCache2.default);
loader = new FakeLoader(gl);
_context.next = 5;
return loader.load(42);
case 5:
res = _context.sent;
expect(res).toMatchObject({
texture: { id: 42 },
width: 2,
height: 2
});
expect(loader.get(42)).toBe(res);
// test with another value
expect(loader.get(43)).toBeUndefined();
_context.next = 11;
return loader.load(43);
case 11:
res = _context.sent;
expect(res).toMatchObject({
texture: { id: 43 },
width: 2,
height: 2
});
expect(loader.get(43)).toBe(res);
loader.dispose();
case 15:
case "end":
return _context.stop();
}
test("WebGLTextureLoaderAsyncHashCache simple usage", _asyncToGenerator(function* () {
const gl = {
deleteTexture: function () {}
};
class FakeLoader extends WebGLTextureLoaderAsyncHashCache {
canLoad(input) {
return typeof input === "number";
}
}, _callee, undefined);
})));
inputHash(input) {
return input;
}
loadNoCache(input) {
return {
promise: Promise.resolve({
texture: { id: input },
width: 2,
height: 2
}),
dispose: () => {}
};
}
}
const loader = new FakeLoader(gl);
let res = yield loader.load(42);
expect(res).toMatchObject({
texture: { id: 42 },
width: 2,
height: 2
});
expect(loader.get(42)).toBe(res);
// test with another value
expect(loader.get(43)).toBeUndefined();
res = yield loader.load(43);
expect(res).toMatchObject({
texture: { id: 43 },
width: 2,
height: 2
});
expect(loader.get(43)).toBe(res);
loader.dispose();
}));
//# sourceMappingURL=WebGLTextureLoaderAsyncHashCache.test.js.map

@@ -1,36 +0,9 @@

"use strict";
import WebGLTextureLoader from "./WebGLTextureLoader";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
class WebGLTextureLoaderSyncHashCache extends WebGLTextureLoader {
constructor(...args) {
var _temp;
var _WebGLTextureLoader2 = require("./WebGLTextureLoader");
var _WebGLTextureLoader3 = _interopRequireDefault(_WebGLTextureLoader2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var WebGLTextureLoaderSyncHashCache = function (_WebGLTextureLoader) {
_inherits(WebGLTextureLoaderSyncHashCache, _WebGLTextureLoader);
function WebGLTextureLoaderSyncHashCache() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, WebGLTextureLoaderSyncHashCache);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = WebGLTextureLoaderSyncHashCache.__proto__ || Object.getPrototypeOf(WebGLTextureLoaderSyncHashCache)).call.apply(_ref, [this].concat(args))), _this), _this.results = new Map(), _this.promises = new Map(), _this._disposed = false, _temp), _possibleConstructorReturn(_this, _ret);
return _temp = super(...args), this.results = new Map(), this.promises = new Map(), this._disposed = false, _temp;
}

@@ -42,52 +15,37 @@ // return a unique representation of the input (typically a hash, or anything that can be used as ref identifier)

_createClass(WebGLTextureLoaderSyncHashCache, [{
key: "dispose",
value: function dispose() {
var _this2 = this;
dispose() {
const { gl, results, promises } = this;
results.forEach(r => {
this.disposeTexture(r.texture);
});
results.clear();
promises.clear();
this._disposed = true;
}
var gl = this.gl,
results = this.results,
promises = this.promises;
disposeTexture(texture) {
this.gl.deleteTexture(texture);
}
results.forEach(function (r) {
_this2.disposeTexture(r.texture);
});
results.clear();
promises.clear();
this._disposed = true;
}
}, {
key: "disposeTexture",
value: function disposeTexture(texture) {
this.gl.deleteTexture(texture);
}
}, {
key: "get",
value: function get(input) {
var hash = this.inputHash(input);
var result = this.results.get(hash);
if (result) return result;
var freshResult = this.getNoCache(input);
this.results.set(hash, freshResult);
return freshResult;
}
get(input) {
const hash = this.inputHash(input);
const result = this.results.get(hash);
if (result) return result;
const freshResult = this.getNoCache(input);
this.results.set(hash, freshResult);
return freshResult;
}
// load() implementation is a dumb fallback on get() but still need to save the promise to guarantee idempotent
// load() implementation is a dumb fallback on get() but still need to save the promise to guarantee idempotent
load(input) {
const hash = this.inputHash(input);
const existing = this.promises.get(hash);
if (existing) return existing;
const promise = Promise.resolve(this.get(input));
this.promises.set(hash, promise);
return promise;
}
}
}, {
key: "load",
value: function load(input) {
var hash = this.inputHash(input);
var existing = this.promises.get(hash);
if (existing) return existing;
var promise = Promise.resolve(this.get(input));
this.promises.set(hash, promise);
return promise;
}
}]);
return WebGLTextureLoaderSyncHashCache;
}(_WebGLTextureLoader3.default);
exports.default = WebGLTextureLoaderSyncHashCache;
export default WebGLTextureLoaderSyncHashCache;
//# sourceMappingURL=WebGLTextureLoaderSyncHashCache.js.map

@@ -1,52 +0,19 @@

"use strict";
import WebGLTextureLoaderSyncHashCache from "./WebGLTextureLoaderSyncHashCache";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _WebGLTextureLoaderSyncHashCache = require("./WebGLTextureLoaderSyncHashCache");
var _WebGLTextureLoaderSyncHashCache2 = _interopRequireDefault(_WebGLTextureLoaderSyncHashCache);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
test("simple usage", function () {
var gl = {
deleteTexture: function deleteTexture() {}
test("simple usage", () => {
const gl = {
deleteTexture: () => {}
};
var FakeLoader = function (_WebGLTextureLoaderSy) {
_inherits(FakeLoader, _WebGLTextureLoaderSy);
function FakeLoader() {
_classCallCheck(this, FakeLoader);
return _possibleConstructorReturn(this, (FakeLoader.__proto__ || Object.getPrototypeOf(FakeLoader)).apply(this, arguments));
class FakeLoader extends WebGLTextureLoaderSyncHashCache {
canLoad(input) {
return typeof input === "number";
}
_createClass(FakeLoader, [{
key: "canLoad",
value: function canLoad(input) {
return typeof input === "number";
}
}, {
key: "inputHash",
value: function inputHash(input) {
return input;
}
}, {
key: "getNoCache",
value: function getNoCache(input) {
return { texture: { id: input }, width: 2, height: 2 };
}
}]);
return FakeLoader;
}(_WebGLTextureLoaderSyncHashCache2.default);
var loader = new FakeLoader(gl);
inputHash(input) {
return input;
}
getNoCache(input) {
return { texture: { id: input }, width: 2, height: 2 };
}
}
const loader = new FakeLoader(gl);
expect(loader.get(42)).toMatchObject({

@@ -53,0 +20,0 @@ texture: { id: 42 },

{
"name": "webgltexture-loader",
"version": "0.10.0-beta.3af8dc87",
"version": "0.12.0-minor.adc60f91",
"description": "load & cache various kind of WebGLTexture with an extensible and loosely coupled system",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet