Skip to content

Commit

Permalink
small refactor and correction
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Felix Brunet committed Aug 14, 2019
1 parent 33fd410 commit d378a96
Show file tree
Hide file tree
Showing 6 changed files with 8,829 additions and 51 deletions.
Loading

1 comment on commit d378a96

@giotiskl
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on this one, I left some line notes for now, there's a couple more things. Code review will be finished a bit more slowly because I'm on holidays atm unfortunately.

Please sign in to comment.