Skip to content

Commit d378a96

Browse files
author
Felix Brunet
committed
small refactor and correction
these are small change in preparation of my feature adding, all explained here with there rational. - FilterItems.ts refactor of `getFiltered` and `getFilteredOut` so they share the same logic code for filtering. this prevent error code duplication and error going with it. also added some doc comment to better distinguish both function. I also maked these two function a bit purer by moving the searchTerm to an optional parameter instead of passing by a shared object. this is a better coding practice and permit to get filtered with a different search term without changing the options small refactor of `shuffle`. there was no reason to call `getFiltered` twice, since `getFiltered` return a new array each time same for the call of `slice()`, since a map alway return a new array. the do-while was followed by a call to "shuffle" in an empty block, so you checked if the new shuffle is different from the last, but shuffled one last time after that. I removed it. the `shouldBeFiltered` function have a misleading name, depending what a "filtered" element mean for you (it is the element that are kept, or the element that are removed?). I refactored it to use typescript "guard" feature, removing the need of using explicit casting (that is error prone). I also checked for "all" direcly in it, so we cannot forget to check for it before calling the function. - utils/shuffle.ts I added typescript generic to keep the type information of the return type the same as the one of the parameter. I also corrected a small comment error. array.slice() do a shallow clone, not a deep clone, and this is what we want. - Filterizr.ts and Filterizr.test.ts updated with the change of parameter of getFiltered - tsconfig.json added "lib" : ["es2016", "esnext", "dom"] to compiler option. this removed some error found by my VisualStudio code intellisence of element not found. by default, lib is only es2015+dom, and the library use some 2016 and next feature.
1 parent 33fd410 commit d378a96

File tree

6 files changed

+8829
-51
lines changed

6 files changed

+8829
-51
lines changed

0 commit comments

Comments
 (0)