Keep errors, elements and comments consistent (#2340)

Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
Lipis 2020-11-05 19:06:18 +02:00 committed by GitHub
parent 2a20c44338
commit 5d295415db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 96 additions and 98 deletions

View File

@ -540,7 +540,7 @@ export const actionChangeSharpness = register({
appState, appState,
); );
const shouldUpdateForNonLinearElements = targetElements.length const shouldUpdateForNonLinearElements = targetElements.length
? targetElements.every((e) => !isLinearElement(e)) ? targetElements.every((el) => !isLinearElement(el))
: !isLinearElementType(appState.elementType); : !isLinearElementType(appState.elementType);
const shouldUpdateForLinearElements = targetElements.length const shouldUpdateForLinearElements = targetElements.length
? targetElements.every(isLinearElement) ? targetElements.every(isLinearElement)

View File

@ -57,9 +57,9 @@ export const copyToClipboard = async (
try { try {
PREFER_APP_CLIPBOARD = false; PREFER_APP_CLIPBOARD = false;
await copyTextToSystemClipboard(json); await copyTextToSystemClipboard(json);
} catch (err) { } catch (error) {
PREFER_APP_CLIPBOARD = true; PREFER_APP_CLIPBOARD = true;
console.error(err); console.error(error);
} }
}; };

View File

@ -561,8 +561,8 @@ class App extends React.Component<ExcalidrawProps, AppState> {
history.clear(); history.clear();
}; };
/** Completely resets scene & history. // Completely resets scene & history.
* Do not use for clear scene user action. */ // Do not use for clear scene user action.
private resetScene = withBatchedUpdates(() => { private resetScene = withBatchedUpdates(() => {
this.scene.replaceAllElements([]); this.scene.replaceAllElements([]);
this.setState({ this.setState({
@ -1467,9 +1467,9 @@ class App extends React.Component<ExcalidrawProps, AppState> {
if (elements) { if (elements) {
this.handleRemoteSceneUpdate(elements, { initFromSnapshot: true }); this.handleRemoteSceneUpdate(elements, { initFromSnapshot: true });
} }
} catch (e) { } catch (error) {
// log the error and move on. other peers will sync us the scene. // log the error and move on. other peers will sync us the scene.
console.error(e); console.error(error);
} }
} }
}; };

View File

@ -167,8 +167,7 @@ class Portal {
const newElements = sceneElements const newElements = sceneElements
.reduce((elements, element) => { .reduce((elements, element) => {
// if the remote element references one that's currently // if the remote element references one that's currently
// edited on local, skip it (it'll be added in the next // edited on local, skip it (it'll be added in the next step)
// step)
if ( if (
element.id === this.app.state.editingElement?.id || element.id === this.app.state.editingElement?.id ||
element.id === this.app.state.resizingElement?.id || element.id === this.app.state.resizingElement?.id ||

View File

@ -108,7 +108,8 @@ export const loadFromBlob = async (
}, },
localAppState, localAppState,
); );
} catch { } catch (error) {
console.error(error.message);
throw new Error(t("alerts.couldNotLoadInvalidFile")); throw new Error(t("alerts.couldNotLoadInvalidFile"));
} }
}; };

View File

@ -69,8 +69,8 @@ export class Library {
Library.libraryCache = JSON.parse(JSON.stringify(items)); Library.libraryCache = JSON.parse(JSON.stringify(items));
resolve(items); resolve(items);
} catch (e) { } catch (error) {
console.error(e); console.error(error);
resolve([]); resolve([]);
} }
}); });
@ -84,9 +84,9 @@ export class Library {
// immediately // immediately
Library.libraryCache = JSON.parse(serializedItems); Library.libraryCache = JSON.parse(serializedItems);
localStorage.setItem(STORAGE_KEYS.LOCAL_STORAGE_LIBRARY, serializedItems); localStorage.setItem(STORAGE_KEYS.LOCAL_STORAGE_LIBRARY, serializedItems);
} catch (e) { } catch (error) {
Library.libraryCache = prevLibraryItems; Library.libraryCache = prevLibraryItems;
console.error(e); console.error(error);
} }
}; };
} }

View File

@ -112,9 +112,9 @@ const restoreElement = (
case "diamond": case "diamond":
return restoreElementWithProperties(element, {}); return restoreElementWithProperties(element, {});
// don't use default case so as to catch a missing an element type case // Don't use default case so as to catch a missing an element type case.
// (we also don't want to throw, but instead return void so we // We also don't want to throw, but instead return void so we filter
// filter out these unsupported elements from the restored array) // out these unsupported elements from the restored array.
} }
}; };
@ -161,7 +161,7 @@ const restoreAppState = (
...nextAppState, ...nextAppState,
offsetLeft: appState.offsetLeft || 0, offsetLeft: appState.offsetLeft || 0,
offsetTop: appState.offsetTop || 0, offsetTop: appState.offsetTop || 0,
/* Migrates from previous version where appState.zoom was a number */ // Migrates from previous version where appState.zoom was a number
zoom: zoom:
typeof appState.zoom === "number" typeof appState.zoom === "number"
? { ? {

View File

@ -75,10 +75,9 @@ const registerValidSW = (swUrl: string, config?: Config) => {
// but the previous service worker will still serve the older // but the previous service worker will still serve the older
// content until all client tabs are closed. // content until all client tabs are closed.
// console.log( console.info(
// "New content is available and will be used when all " + "New content is available and will be used when all tabs for this page are closed.",
// "tabs for this page are closed.", );
// );
// Execute callback // Execute callback
if (config && config.onUpdate) { if (config && config.onUpdate) {
@ -89,7 +88,7 @@ const registerValidSW = (swUrl: string, config?: Config) => {
// It's the perfect time to display a // It's the perfect time to display a
// "Content is cached for offline use." message. // "Content is cached for offline use." message.
// console.log("Content is cached for offline use."); console.info("Content is cached for offline use.");
// Execute callback // Execute callback
if (config && config.onSuccess) { if (config && config.onSuccess) {
@ -128,10 +127,11 @@ const checkValidServiceWorker = (swUrl: string, config?: Config) => {
registerValidSW(swUrl, config); registerValidSW(swUrl, config);
} }
}) })
.catch(() => { .catch((error) => {
// console.log( console.info(
// "No internet connection found. App is running in offline mode.", "No internet connection found. App is running in offline mode.",
// ); error.message,
);
}); });
}; };

View File

@ -1594,8 +1594,7 @@ it(
mouse.up(100, 100); mouse.up(100, 100);
// Select first rectangle while keeping third one selected. // Select first rectangle while keeping third one selected.
// Third rectangle is selected because it was the last element // Third rectangle is selected because it was the last element to be created.
// to be created.
mouse.reset(); mouse.reset();
Keyboard.withModifierKeys({ shift: true }, () => { Keyboard.withModifierKeys({ shift: true }, () => {
mouse.click(); mouse.click();
@ -1616,8 +1615,7 @@ it(
}); });
expect(API.getSelectedElements().length).toBe(3); expect(API.getSelectedElements().length).toBe(3);
// pointer down o first rectangle that is // Pointer down o first rectangle that is part of the group
// part of the group
mouse.reset(); mouse.reset();
Keyboard.withModifierKeys({ shift: true }, () => { Keyboard.withModifierKeys({ shift: true }, () => {
mouse.down(); mouse.down();