Commit a59c3741 authored by marsandheart's avatar marsandheart

add prettier,redux,rematch

parent ad6f5a92
module.exports = {
printWidth: 100,
parser: "flow",
singleQuote: true,
arrowParens: 'always',
};
\ No newline at end of file
...@@ -3,18 +3,24 @@ ...@@ -3,18 +3,24 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@rematch/core": "^1.3.0",
"@testing-library/jest-dom": "^4.2.4", "@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2", "@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2", "@testing-library/user-event": "^7.1.2",
"react": "^16.12.0", "react": "^16.12.0",
"react-dom": "^16.12.0", "react-dom": "^16.12.0",
"react-scripts": "3.3.0" "react-redux": "^7.1.3",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0",
"redux": "^4.0.4"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject",
"prt": "node prt.js"
}, },
"eslintConfig": { "eslintConfig": {
"extends": "react-app" "extends": "react-app"
...@@ -30,5 +36,8 @@ ...@@ -30,5 +36,8 @@
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
},
"devDependencies": {
"prettier": "1.19.1"
} }
} }
const fs = require("fs");
const path = require("path");
const prettier = require("prettier");
const config = require("./.prettierrc");
const dir = './src';
mapAndFormat(dir);
function mapAndFormat(filePath) {
let files = fs.readdirSync(filePath);
files.forEach(fileName => {
const fullFIleName = `${filePath}/${fileName}`;
const stat = fs.statSync(fullFIleName);
const isDirectory = stat.isDirectory(fullFIleName);
const isJSFile = stat.isFile(fullFIleName) && (path.extname(fileName) === '.js');
if (isDirectory) {
mapAndFormat(fullFIleName);
} else if (isJSFile) {
const text = fs.readFileSync(fullFIleName, 'utf8');
const formatted = prettier.format(text, config);
fs.writeFileSync(fullFIleName, formatted);
}
});
}
...@@ -15,9 +15,7 @@ const isLocalhost = Boolean( ...@@ -15,9 +15,7 @@ const isLocalhost = Boolean(
// [::1] is the IPv6 localhost address. // [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' || window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4. // 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match( window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
); );
export function register(config) { export function register(config) {
...@@ -57,7 +55,7 @@ export function register(config) { ...@@ -57,7 +55,7 @@ export function register(config) {
function registerValidSW(swUrl, config) { function registerValidSW(swUrl, config) {
navigator.serviceWorker navigator.serviceWorker
.register(swUrl) .register(swUrl)
.then(registration => { .then((registration) => {
registration.onupdatefound = () => { registration.onupdatefound = () => {
const installingWorker = registration.installing; const installingWorker = registration.installing;
if (installingWorker == null) { if (installingWorker == null) {
...@@ -93,7 +91,7 @@ function registerValidSW(swUrl, config) { ...@@ -93,7 +91,7 @@ function registerValidSW(swUrl, config) {
}; };
}; };
}) })
.catch(error => { .catch((error) => {
console.error('Error during service worker registration:', error); console.error('Error during service worker registration:', error);
}); });
} }
...@@ -103,7 +101,7 @@ function checkValidServiceWorker(swUrl, config) { ...@@ -103,7 +101,7 @@ function checkValidServiceWorker(swUrl, config) {
fetch(swUrl, { fetch(swUrl, {
headers: { 'Service-Worker': 'script' } headers: { 'Service-Worker': 'script' }
}) })
.then(response => { .then((response) => {
// Ensure service worker exists, and that we really are getting a JS file. // Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type'); const contentType = response.headers.get('content-type');
if ( if (
...@@ -111,7 +109,7 @@ function checkValidServiceWorker(swUrl, config) { ...@@ -111,7 +109,7 @@ function checkValidServiceWorker(swUrl, config) {
(contentType != null && contentType.indexOf('javascript') === -1) (contentType != null && contentType.indexOf('javascript') === -1)
) { ) {
// No service worker found. Probably a different app. Reload the page. // No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => { navigator.serviceWorker.ready.then((registration) => {
registration.unregister().then(() => { registration.unregister().then(() => {
window.location.reload(); window.location.reload();
}); });
...@@ -122,15 +120,13 @@ function checkValidServiceWorker(swUrl, config) { ...@@ -122,15 +120,13 @@ function checkValidServiceWorker(swUrl, config) {
} }
}) })
.catch(() => { .catch(() => {
console.log( console.log('No internet connection found. App is running in offline mode.');
'No internet connection found. App is running in offline mode.'
);
}); });
} }
export function unregister() { export function unregister() {
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => { navigator.serviceWorker.ready.then((registration) => {
registration.unregister(); registration.unregister();
}); });
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment