Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added prettier config #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:flowtype/recommended"
"plugin:flowtype/recommended",
"prettier"
],
"globals": {
"__DEV__": false
Expand All @@ -23,23 +24,14 @@
"plugins": [
"flowtype",
"react",
"sort-imports-es6-autofix"
"sort-imports-es6-autofix",
"prettier"
],
"rules": {
"curly": [
"error"
],
"indent": [
"error",
2,
{
"SwitchCase": 1
}
],
"linebreak-style": [
"error",
"unix"
],
"prettier/prettier": "error",
"no-console": "off",
"no-const-assign": 1,
"no-extra-semi": 0,
Expand All @@ -51,10 +43,6 @@
"prefer-const": [
"error"
],
"quotes": [
"error",
"single"
],
"react/jsx-no-bind": [
"error"
],
Expand Down
49 changes: 26 additions & 23 deletions lib/ImageWorker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import React, { Component } from 'react';
import React, { Component } from "react";

const webWorkerScript = `
self.addEventListener('message', event => {
Expand All @@ -15,35 +15,33 @@ const webWorkerScript = `
})
`;


type ImageWorkerProps = {
src: string,
placeholder?: string | Function,
style?: Object,
imageClass?: string,
containerClass?: string,
}
containerClass?: string
};

type ImageWorkerState = {
isLoading: boolean,
imgSrc: string
}

};

const wrappedComponent = WrappedComponent => props => {
return <WrappedComponent {...props} />;
};

class ImageWorker extends Component<ImageWorkerProps, ImageWorkerState> {
image: HTMLImageElement;
worker = new Worker(URL.createObjectURL(
new Blob([webWorkerScript], { type: 'application/javascript' })
))
worker = new Worker(
URL.createObjectURL(new Blob([webWorkerScript], { type: "application/javascript" }))
);

state = {
isLoading: true,
imgSrc: ''
}
imgSrc: ""
};
constructor(props: ImageWorkerProps) {
super(props);
this.worker.onmessage = (event: Object) => {
Expand All @@ -65,11 +63,11 @@ class ImageWorker extends Component<ImageWorkerProps, ImageWorkerState> {

renderPlaceholder() {
const { placeholder, style } = this.props;
if (typeof placeholder === 'function') {
if (typeof placeholder === "function") {
const PlaceholderComponent = wrappedComponent(placeholder);
return <PlaceholderComponent />;
} else if (typeof placeholder === 'string') {
return <img src={placeholder} style={{ ...style }} alt='placeholder' />;
} else if (typeof placeholder === "string") {
return <img src={placeholder} style={{ ...style }} alt="placeholder" />;
} else {
return null;
}
Expand All @@ -78,27 +76,32 @@ class ImageWorker extends Component<ImageWorkerProps, ImageWorkerState> {
loadImage = (url: string) => {
const image = new Image();
this.image = image;

image.src = url;
image.decode !== undefined ? image.decode().then(this.onLoad).catch(this.onLoad) : image.onload = this.onLoad;
}
image.decode !== undefined
? image
.decode()
.then(this.onLoad)
.catch(this.onLoad)
: (image.onload = this.onLoad);
};

onLoad = () => {
this.setState({
imgSrc: this.image.src,
isLoading: false
});
}
};

render() {
const { style, imageClass, containerClass } = this.props;
return (
<div className={containerClass}>
{
this.state.isLoading ? this.renderPlaceholder() :
<img src={this.state.imgSrc}
style={{ ...style }} className={imageClass} alt='worker' />
}
{this.state.isLoading ? (
this.renderPlaceholder()
) : (
<img src={this.state.imgSrc} style={{ ...style }} className={imageClass} alt="worker" />
)}
</div>
);
}
Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-worker-image",
"version": "1.0.11",
"version": "1.0.12",
"description": "React component to fetch image resources via web workers",
"main": "index.js",
"scripts": {
Expand All @@ -27,13 +27,20 @@
"babel-preset-react": "^6.24.1",
"babel-preset-react-app": "^3.1.1",
"eslint": "^4.17.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-flowtype": "^2.42.0",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.6.1",
"eslint-plugin-sort-imports-es6-autofix": "^0.2.2",
"flow-bin": "^0.64.0"
"flow-bin": "^0.64.0",
"prettier": "^1.10.2"
},
"peerDependencies": {
"react": "^15.0.0-0 || ^16.0.0-0",
"react-dom": "^15.0.0-0 || ^16.0.0-0"
},
"prettier": {
"printWidth": 100,
"parser": "flow"
}
}
49 changes: 30 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1168,12 +1168,25 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

eslint-config-prettier@^2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-2.9.0.tgz#5ecd65174d486c22dff389fe036febf502d468a3"
dependencies:
get-stdin "^5.0.1"

eslint-plugin-flowtype@^2.42.0:
version "2.42.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.42.0.tgz#7fcc98df4ed9482a22ac10ba4ca48d649c4c733a"
dependencies:
lodash "^4.15.0"

eslint-plugin-prettier@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-2.6.0.tgz#33e4e228bdb06142d03c560ce04ec23f6c767dd7"
dependencies:
fast-diff "^1.1.1"
jest-docblock "^21.0.0"

eslint-plugin-react@^7.6.1:
version "7.6.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.6.1.tgz#5d0e908be599f0c02fbf4eef0c7ed6f29dff7633"
Expand Down Expand Up @@ -1316,6 +1329,10 @@ fast-deep-equal@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff"

fast-diff@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.1.2.tgz#4b62c42b8e03de3f848460b639079920695d0154"

fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
Expand Down Expand Up @@ -1455,6 +1472,10 @@ gauge@~2.7.3:
strip-ansi "^3.0.1"
wide-align "^1.1.0"

get-stdin@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398"

getpass@^0.1.1:
version "0.1.7"
resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa"
Expand Down Expand Up @@ -1764,6 +1785,10 @@ isstream@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"

jest-docblock@^21.0.0:
version "21.2.0"
resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414"

js-tokens@^3.0.0, js-tokens@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
Expand Down Expand Up @@ -1855,7 +1880,7 @@ lodash@^4.15.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:
loose-envify@^1.0.0, loose-envify@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
dependencies:
Expand Down Expand Up @@ -2097,6 +2122,10 @@ preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"

prettier@^1.10.2:
version "1.10.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.10.2.tgz#1af8356d1842276a99a5b5529c82dd9e9ad3cc93"

private@^0.1.6, private@^0.1.7:
version "0.1.8"
resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff"
Expand Down Expand Up @@ -2151,24 +2180,6 @@ rc@^1.1.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-dom@^16.2.0:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.2.0.tgz#69003178601c0ca19b709b33a83369fe6124c044"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.0"

react@^16.2.0:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.2.0.tgz#a31bd2dab89bff65d42134fa187f24d054c273ba"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.0"

readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.2.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c"
Expand Down