-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy.js
More file actions
42 lines (32 loc) · 873 Bytes
/
Copy pathproxy.js
File metadata and controls
42 lines (32 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Build an image loader that logs requests before actually loading the image.
class ImageLoader {
load() {
throw new Error('Method not implemented');
}
}
class RealImage extends ImageLoader {
constructor(filename) {
super();
this.filename = filename;
}
load() {
console.log(`Loading image: ${this.filename}`);
}
}
class ImageProxy extends ImageLoader {
constructor(filename) {
super();
this.filename = filename;
this.realImage = null;
}
load() {
console.log(`[Proxy] Intercepting request to load image: ${this.filename}`);
if (!this.realImage) {
this.realImage = new RealImage(this.filename);
}
this.realImage.load();
}
}
const filename = "image1.jpg";
const image = new ImageProxy(filename);
image.load();