Skip to content

Commit 2158d26

Browse files
committed
fix: use less lodash in kernel-manager
1 parent 00b85c1 commit 2158d26

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lib/kernel-manager.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { TextEditor, Grammar } from "atom";
2-
import _ from "lodash";
2+
import map from "lodash/map";
3+
import mapKeys from "lodash/mapKeys";
4+
import sortBy from "lodash/sortBy";
35
import { findAll as kernelSpecsFindAll } from "kernelspecs";
46
import { shell } from "electron";
57
import ZMQKernel from "./zmq-kernel";
@@ -81,13 +83,12 @@ export class KernelManager {
8183

8284
async update(): Promise<KernelspecMetadata[]> {
8385
const kernelSpecs = await kernelSpecsFindAll();
84-
this.kernelSpecs = _.sortBy(
85-
_.map(
86-
_.mapKeys(kernelSpecs, function (value, key) {
87-
return (value.spec.name = key);
88-
}),
89-
"spec"
90-
),
86+
87+
const kernelResourcesDict = mapKeys(kernelSpecs, function (value, key) {
88+
return (value.spec.name = key);
89+
});
90+
this.kernelSpecs = sortBy(
91+
map(kernelResourcesDict, "spec"),
9192
(spec) => spec.display_name
9293
);
9394
return this.kernelSpecs;
@@ -169,8 +170,9 @@ export class KernelManager {
169170
atom.notifications.addError(message, options);
170171
} else {
171172
const message = "Hydrogen Kernels updated:";
173+
const displayNames = map(kernelSpecs, "display_name"); // kernelSpecs.map((kernelSpec) => kernelSpec.display_name)
172174
const options = {
173-
detail: _.map(kernelSpecs, "display_name").join("\n"),
175+
detail: displayNames.join("\n"),
174176
};
175177
atom.notifications.addInfo(message, options);
176178
}

spec/kernel-manager-spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe("Kernel manager", () => {
5959

6060
describe("getAllKernelSpecs", () => {
6161
it("should update kernelspecs if no kernelspecs are stored", async () => {
62+
// TODO why does the unit tests mock kernelSpecs with a string
6263
spyOn(manager, "update").and.returnValue("specs");
6364
expect(await manager.getAllKernelSpecs()).toBe("specs");
6465
expect(manager.update).toHaveBeenCalled();

0 commit comments

Comments
 (0)