Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 44d5d86

Browse files
committed
more async await
1 parent 0463c16 commit 44d5d86

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

lib/views/git-timings-view.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,17 @@ class WaterfallWidget extends React.Component {
322322
this.setState(s => ({collapsed: !s.collapsed}));
323323
}
324324

325-
handleExportClick(e) {
325+
async handleExportClick(e) {
326326
e.preventDefault();
327327
const json = JSON.stringify(this.props.markers.map(m => m.serialize()), null, ' ');
328328
const buffer = new TextBuffer({text: json});
329-
dialog.showSaveDialog({
329+
const {filePath} = await dialog.showSaveDialog({
330330
defaultPath: 'git-timings.json',
331-
}).then(({filePath}) => {
332-
if (!filePath) { return; }
333-
buffer.saveAs(filePath);
334331
});
332+
if (!filePath) {
333+
return;
334+
}
335+
buffer.saveAs(filePath);
335336
}
336337
}
337338

@@ -419,22 +420,23 @@ export default class GitTimingsView extends React.Component {
419420
);
420421
}
421422

422-
handleImportClick(e) {
423+
async handleImportClick(e) {
423424
e.preventDefault();
424-
dialog.showOpenDialog({
425+
const {filePaths} = await dialog.showOpenDialog({
425426
properties: ['openFile'],
426-
}).then(async ({filePaths}) => {
427-
if (!filePaths.length) { return; }
428-
const filename = filePaths[0];
429-
try {
430-
const contents = await fs.readFile(filename, {encoding: 'utf8'});
431-
const data = JSON.parse(contents);
432-
const restoredMarkers = data.map(item => Marker.deserialize(item));
433-
GitTimingsView.restoreGroup(restoredMarkers);
434-
} catch (_err) {
435-
atom.notifications.addError(`Could not import timings from ${filename}`);
436-
}
437427
});
428+
if (!filePaths.length) {
429+
return;
430+
}
431+
const filename = filePaths[0];
432+
try {
433+
const contents = await fs.readFile(filename, {encoding: 'utf8'});
434+
const data = JSON.parse(contents);
435+
const restoredMarkers = data.map(item => Marker.deserialize(item));
436+
GitTimingsView.restoreGroup(restoredMarkers);
437+
} catch (_err) {
438+
atom.notifications.addError(`Could not import timings from ${filename}`);
439+
}
438440
}
439441

440442
serialize() {

0 commit comments

Comments
 (0)