Review 1
Opened this issue · 0 comments
tshemsedinov commented
- Try to use
has
method here and move everything inside is statement, and throw is vertex already exists: https://github.com/kreslavskiy/graphs/blob/a7beb1f5b6dffb067217faed4bac46d225885db0/graph.js#L46 - Use
has
: https://github.com/kreslavskiy/graphs/blob/a7beb1f5b6dffb067217faed4bac46d225885db0/graph.js#L58 - Compare by reference: https://github.com/kreslavskiy/graphs/blob/a7beb1f5b6dffb067217faed4bac46d225885db0/graph.js#L52-L63
- Optimize: https://github.com/kreslavskiy/graphs/blob/a7beb1f5b6dffb067217faed4bac46d225885db0/graph.js#L6
const deserialize = (src) => vm.createScript(`({' + str + '})`).runInThisContext();
- Decompose into 2 methods
filterByFields
,filterByLinks
and all them fromselect
method: https://github.com/kreslavskiy/graphs/blob/a7beb1f5b6dffb067217faed4bac46d225885db0/graph.js#L65-L88 - Rename: https://github.com/kreslavskiy/graphs/blob/a7beb1f5b6dffb067217faed4bac46d225885db0/graph.js#L90-L96
- Easy way to convert iterable to array:
[...map.entries()]
https://github.com/kreslavskiy/graphs/blob/a7beb1f5b6dffb067217faed4bac46d225885db0/graph.js#L100 - Use eslint and prettier
- Rewrite: https://github.com/kreslavskiy/graphs/blob/a7beb1f5b6dffb067217faed4bac46d225885db0/graph.js#L98-L106
async createFile(fileName) {
const vertices = [...this.vertices.entries()];
const data = JSON.stringify(vertices);
await fs.promises.appendFile(`${fileName}.txt`, data);
},