feat: add state invalidation to BasePaginator class#1734
feat: add state invalidation to BasePaginator class#1734arnautov-anton wants to merge 1 commit intomasterfrom
Conversation
|
Size Change: +350 B (+0.09%) Total Size: 381 kB 📦 View Changed
|
2312c6f to
836b577
Compare
836b577 to
bd6d38e
Compare
bd6d38e to
2e509fb
Compare
| if (!this.canExecuteQuery(direction)) return; | ||
| const isFirstPage = typeof this.items === 'undefined'; | ||
| if (isFirstPage) { | ||
| this.state.next(this.getStateBeforeFirstQuery()); |
There was a problem hiding this comment.
Removing this is potentially breaking
There was a problem hiding this comment.
As this is setting state before the query is executed. This is a hook that can be used by integrators to adjust the state before the first query.
There was a problem hiding this comment.
State before the first query should always be initialState unless invalidated. When invalidated and re-fetched, the state is kept until there's something to replace it with to prevent the data -> no data -> new data UI blinking.
|
|
||
| if (this._isCursorPagination) { | ||
| stateUpdate.cursor = { next: next || null, prev: prev || null }; | ||
| stateUpdate.cursor = { next, prev }; |
There was a problem hiding this comment.
Value null has a meaning that there are no more pages to retrieve. Are we getting null from results.next / results.prev or if we arrived at the end it is undefined? undefined in paginator was dedicated for pagination not started yet.
There was a problem hiding this comment.
Oh - there were no particular null checks anywhere and tests (both manual and written) passed without any hiccups. As for the BE API - if you finish paginating, no cursor - at least for this particular API (reactions) - seems to be returned.
Description of the changes, What, Why and How?
Adds state invalidation logic to a
BasePaginatorclass, adjusts types. Super-simplifiedreact-queryfeature (invalidateQueries).Ref: GetStream/stream-chat-react#3173