Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@internetarchive/lazy-loader-service

Package Overview
Dependencies
Maintainers
13
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@internetarchive/lazy-loader-service - npm Package Compare versions

Comparing version 0.2.0-alpha.1 to 0.2.0-alpha.2

7

dist/src/lazy-loader-service.js

@@ -88,3 +88,8 @@ import { __awaiter } from "tslib";

else {
this.emitter.emit('scriptLoadFailed', options.src, error);
// only emit a failure event from the last attempt, which has not been retried.
// otherwise you get failure events from each script tag, when we're really
// only interested that the entire chain failed
if (!hasBeenRetried) {
this.emitter.emit('scriptLoadFailed', options.src, error);
}
originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError(error);

@@ -91,0 +96,0 @@ reject(error);

@@ -159,2 +159,36 @@ import { __awaiter } from "tslib";

}));
it('Emits the expected number of retry events', () => __awaiter(void 0, void 0, void 0, function* () {
const container = (yield fixture(html ` <div></div> `));
const lazyLoader = new LazyLoaderService({
container,
retryCount: 4,
retryInterval: 0.01,
});
let retryEvents = 0;
lazyLoader.on('scriptLoadRetried', () => {
retryEvents += 1;
});
try {
yield lazyLoader.loadScript({ src: '/base/test/blahblah.js' });
}
catch (_a) { }
expect(retryEvents).to.equal(4);
}));
it('Only emits a single failure event if there are multiple retry attempts', () => __awaiter(void 0, void 0, void 0, function* () {
const container = (yield fixture(html ` <div></div> `));
const lazyLoader = new LazyLoaderService({
container,
retryCount: 4,
retryInterval: 0.01,
});
let failureEvents = 0;
lazyLoader.on('scriptLoadFailed', () => {
failureEvents += 1;
});
try {
yield lazyLoader.loadScript({ src: '/base/test/blahblah.js' });
}
catch (_b) { }
expect(failureEvents).to.equal(1);
}));
it('Retries the specified number of times', () => __awaiter(void 0, void 0, void 0, function* () {

@@ -170,3 +204,3 @@ const container = (yield fixture(html ` <div></div> `));

}
catch (_a) { }
catch (_c) { }
const scriptTags = container.querySelectorAll('script');

@@ -173,0 +207,0 @@ expect(scriptTags.length).to.equal(6);

2

package.json
{
"name": "@internetarchive/lazy-loader-service",
"version": "0.2.0-alpha.1",
"version": "0.2.0-alpha.2",
"description": "A small library to lazy load javascript with a Promise",

@@ -5,0 +5,0 @@ "license": "AGPL-3.0-only",

@@ -150,3 +150,8 @@ import { createNanoEvents, Unsubscribe } from 'nanoevents';

} else {
this.emitter.emit('scriptLoadFailed', options.src, error);
// only emit a failure event from the last attempt, which has not been retried.
// otherwise you get failure events from each script tag, when we're really
// only interested that the entire chain failed
if (!hasBeenRetried) {
this.emitter.emit('scriptLoadFailed', options.src, error);
}
originalOnError?.(error);

@@ -153,0 +158,0 @@ reject(error);

@@ -186,2 +186,42 @@ import { expect, fixture, html } from '@open-wc/testing';

it('Emits the expected number of retry events', async () => {
const container = (await fixture(html` <div></div> `)) as HTMLElement;
const lazyLoader = new LazyLoaderService({
container,
retryCount: 4,
retryInterval: 0.01,
});
let retryEvents = 0;
lazyLoader.on('scriptLoadRetried', () => {
retryEvents += 1;
});
try {
await lazyLoader.loadScript({ src: '/base/test/blahblah.js' });
} catch {}
expect(retryEvents).to.equal(4);
});
it('Only emits a single failure event if there are multiple retry attempts', async () => {
const container = (await fixture(html` <div></div> `)) as HTMLElement;
const lazyLoader = new LazyLoaderService({
container,
retryCount: 4,
retryInterval: 0.01,
});
let failureEvents = 0;
lazyLoader.on('scriptLoadFailed', () => {
failureEvents += 1;
});
try {
await lazyLoader.loadScript({ src: '/base/test/blahblah.js' });
} catch {}
expect(failureEvents).to.equal(1);
});
it('Retries the specified number of times', async () => {

@@ -188,0 +228,0 @@ const container = (await fixture(html` <div></div> `)) as HTMLElement;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc