-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pagination, small refactor and correction #124
base: master
Are you sure you want to change the base?
Conversation
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.
A new commit, adding a first version of pagination feature, I added new test to be sure it work with other feature, and I fixed some test who did not work or where not optimal :
this should fix #113 once it's done, and be a part of what needed to fix #90. |
@up |
I did not work on this since my last commit, but I have a project waiting who still need the filter + pagination, so I will have to restart working on this eventually. |
I have one project in which I would like to do pagination, so I could test it for you. When are you going to back to your project? |
Hey @xileftenurb, I think a lot of people need pagination in their projects, so I wanted to implement it myself, but then saw your PR (looks pretty cool btw). I have a suggestion, maybe instead of passing category into |
these are small change in preparation of my feature adding, all
explained here with there rational.
refactor of
getFiltered
andgetFilteredOut
so they share the same logiccode 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 callgetFiltered
twice, since
getFiltered
return a new array each timesame 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.
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.
updated with the change of parameter of getFiltered
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.