wasdk / WebAssemblyStudio

Learn, Teach, Work and Play in the WebAssembly Studio
http://webassembly.studio
MIT License
2.92k stars 273 forks source link

Possible code duplication #457

Open BlueMagnificent opened 4 years ago

BlueMagnificent commented 4 years ago

There seems to be a sort of code duplication here:

https://github.com/wasdk/WebAssemblyStudio/blob/49afdefc505f529ff20e9cb448751093eead1dde/src/utils/Template.ts#L72-L83

Given that the below code is to handle such case: https://github.com/wasdk/WebAssemblyStudio/blob/49afdefc505f529ff20e9cb448751093eead1dde/src/models/types.ts#L234-L261

The default value for an unknown file.type in the above src\utils\Template.ts snippet is an empty string, while its equivalent in getIconForFileType of src\models\types.ts is the string "txt-ext-file-icon". However from observing rendered files in the DirectoryTree, these two default values still give the same icon.

We can correct this duplication by modifying: https://github.com/wasdk/WebAssemblyStudio/blob/49afdefc505f529ff20e9cb448751093eead1dde/src/utils/Template.ts#L22 to

import { File, FileType, Problem, Directory, getIconForFileType } from "../models";

and replacing: https://github.com/wasdk/WebAssemblyStudio/blob/49afdefc505f529ff20e9cb448751093eead1dde/src/utils/Template.ts#L72-L83 with

let icon = getIconForFileType(file.type);

It would be appropriate to note that without the above modifications the code still works well. I'm just pointing it out since it would make it easy to include additional file types later.

mollthecoder commented 3 years ago

You should probably open a pull request.