Skip to content

Commit

Permalink
Samples for throttles loading
Browse files Browse the repository at this point in the history
  • Loading branch information
hejny committed Sep 10, 2021
1 parent 43cbefd commit 6627288
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 2 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@types/jest": "^24.0.13",
"codecov": "^3.5.0",
"express": "^4.17.1",
"express-throttle-bandwidth": "^1.0.1",
"glob-promise": "^4.2.0",
"jest": "^24.8.0",
"onchange": "^3.3.0",
Expand Down
5 changes: 4 additions & 1 deletion samples/_samplesServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const serveStatic = require('serve-static');
const serveIndex = require('serve-index');
const path = require('path');
const opn = require('open');
const throttle = require('express-throttle-bandwidth');

// TODO: as indipendent library

Expand All @@ -12,9 +13,11 @@ const staticBasePath = path.join(__dirname, '..');

const app = express();

app.use(throttle(10 /* bits per second */));
app.use(serveStatic(staticBasePath, { index: false }));
app.use(serveIndex(staticBasePath, { icons: true }));
app.listen(PORT);

console.log(`Static server listening on port ${PORT}.`);
opn(`http://localhost:${PORT}/samples`);
// TODO: Only if not opened
// !!! opn(`http://localhost:${PORT}/samples`);
3 changes: 3 additions & 0 deletions samples/assets/common.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
img {
max-width: 50vw;
}
249 changes: 249 additions & 0 deletions samples/assets/images/image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added samples/assets/images/simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion samples/forAllImagesInElement.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<link rel="stylesheet" type="text/css" href="./assets/common.css" />
</head>
<body>
<canvas id="scene" width="500" height="500"></canvas>
<img src="./assets/images/image.svg" />
<img src="./assets/images/simple.png" />

<script type="module">
import { forAllImagesInElement } from '../dist/main.js';
Expand Down
2 changes: 2 additions & 0 deletions src/functions/forAllImagesInElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export async function forAllImagesInElement(
rejectWhenNotLoaded = false,
timeout = 1500,
): Promise<void> {

// TODO: !!! Also with media and pictures
try {
await Promise.all(
// TODO: How to handle console.info
Expand Down

0 comments on commit 6627288

Please sign in to comment.