Skip to content

Commit 5dd7296

Browse files
authored
fix(component): Bug fixes
2 parents 73fcd85 + 63b9d3a commit 5dd7296

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,5 @@
4444
"verifyConditions": "condition-circle"
4545
},
4646
"dependencies": {
47-
"lodash": "^4.17.4"
4847
}
4948
}

src/index.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {assign} from "lodash";
21
import * as React from "react";
32

43
export type DivProps = React.HTMLProps<HTMLImageElement>;
@@ -19,7 +18,7 @@ export interface ProgressiveImageState {
1918

2019
export class ProgressiveImage extends React.Component<ProgressiveImageProps & DivProps & ImageProps, ProgressiveImageState> {
2120

22-
private clonedProps: React.HTMLProps<HTMLDivElement | HTMLImageElement> = {};
21+
private clonedProps: React.HTMLProps<HTMLDivElement & HTMLImageElement> = {};
2322

2423
static defaultProps = {
2524
transitionTime: 500,
@@ -30,24 +29,37 @@ export class ProgressiveImage extends React.Component<ProgressiveImageProps & Di
3029
const {src, preview} = this.props;
3130
this.setState({ src: "", blur: 10 });
3231
this.cloneProps();
33-
fetch(preview)
34-
.then(() => this.setState({ src: preview, blur: 10 }))
35-
.then(() => fetch(src))
36-
.then(() => this.setState({ src, blur: 0 }));
32+
this.fetch(preview)
33+
.then(previewDataURI => this.setState({ src: previewDataURI, blur: 10 }))
34+
.then(() => this.fetch(src))
35+
.then(srcDataURI => this.setState({ src: srcDataURI, blur: 0 }));
3736
}
38-
3937
render() {
4038
const {src, style, background} = this.props;
4139
return background ?
42-
<div style={assign(this.getBackgroundStyle(), style)} {...this.clonedProps} />
43-
:
44-
<img src={src} style={assign(this.getStyle(), style)} {...this.clonedProps} />
45-
;
40+
<div style={Object.assign(this.getBackgroundStyle(), style)} {...this.clonedProps} />
41+
:
42+
<img src={src} style={Object.assign(this.getStyle(), style)} {...this.clonedProps} />
43+
;
44+
}
45+
46+
private fetch(uri: string): Promise<string> {
47+
return new Promise(resolve => {
48+
fetch(uri)
49+
.then(response => response.blob())
50+
.then(blob => {
51+
const fp = new FileReader();
52+
fp.onload = () => {
53+
resolve(fp.result as string);
54+
};
55+
fp.readAsDataURL(blob);
56+
});
57+
});
4658
}
4759

4860
private cloneProps() {
4961
Object.keys(this.props)
50-
.filter(prop => ["style", "src", "preview", "background"].indexOf(prop) === -1)
62+
.filter(prop => ["style", "src", "preview", "background", "transitionTime", "timingFunction"].indexOf(prop) === -1)
5163
.forEach(prop => this.clonedProps[prop] = this.props[prop]);
5264
}
5365

@@ -65,6 +77,6 @@ export class ProgressiveImage extends React.Component<ProgressiveImageProps & Di
6577
const style = {
6678
backgroundImage: `url(${src})`
6779
};
68-
return assign(style, this.getStyle());
80+
return Object.assign(style, this.getStyle());
6981
}
70-
}
82+
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "es2015",
44
"module": "commonjs",
55
"moduleResolution": "node",
66
"jsx": "react",

0 commit comments

Comments
 (0)