You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #907 [3.x] Re-worked pagination to not mutate the api classes (GrahamCampbell)
This PR was squashed before being merged into the 3.0.x-dev branch.
Discussion
----------
This re-works pagination to avoid mutating the API classes. It took a few attempts to get the implementation details right. Let me explain why I chose to use clone:
1. If we were to use `new static(...)`, then I would have had to have made the abstract api constructor final. This could cause problems for people mocking the api classes, and also limits the possibility to thunk up arguments to the api classes, say if we want to introduce an api class which takes an extra parameter which is always used (this is common place in the gitlab fork of this library).
2. Is there another way to do things without making the constructor final or using clone? Well, we could have every api object implement perPage for themselves. This is kinda cumbersome though, and I don't think we want to do this.
---
This PR partially addresses #904.
So, I think cloning then setting the private property, within the abstract api class is the way to go, and nicely separates responsibilities. Classes that extend the abstract api class cannot mutate the property, and outsiders also cannot either. They have to call perPage which gives a fresh instance (one we've cloned).
Commits
-------
54c652c Re-worked pagination to not mutate the api classes
4ba3e48 Avoid needing getPerPage and perPage
decf105 Restored test coverage
0 commit comments