Skip to content

Commit b2cf097

Browse files
authored
Update doc [skip ci] (#229)
1 parent 35e32b2 commit b2cf097

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,9 @@ Disadvantages:
332332
Usage is the following:
333333

334334
```php
335-
$sort = Sort::only(['id', 'name'])->withOrderString('id');
335+
$sort = Sort::only(['id', 'name']);
336336

337-
$dataReader = (new MyDataReader(...))
338-
->withSort($sort);
337+
$dataReader = (new MyDataReader(...))->withSort($sort);
339338

340339
$paginator = (new KeysetPaginator($dataReader))
341340
->withPageSize(10)
@@ -345,27 +344,26 @@ $paginator = (new KeysetPaginator($dataReader))
345344
When displaying first page ID (or another field name to paginate by) of the item displayed last is used with `withNextPageToken()`
346345
to get next page.
347346

348-
#### Page-by-page navigation
347+
#### Iterate through all pages
349348

350349
Both `OffsetPaginator` and `KeysetPaginator` provide `nextPage()` and `previousPage()` methods for easy page-by-page data reading:
351350

352351
```php
353352
$dataReader = (new QueryDataReader($query))->withSort(Sort::only(['id']));
354-
$paginator = (new KeysetPaginator($dataReader))->withPageSize(1000);
355353

356-
// Iterate through all pages
357354
for (
358-
$currentPaginator = $paginator;
359-
$currentPaginator !== null;
360-
$currentPaginator = $currentPaginator->nextPage()
355+
$paginator = (new KeysetPaginator($dataReader))->withPageSize(1000);
356+
$paginator !== null;
357+
$paginator = $paginator->nextPage()
361358
) {
362-
foreach ($currentPaginator->read() as $data) {
359+
foreach ($paginator->read() as $data) {
363360
// Process each item
364361
}
365362
}
366363
```
367364

368-
The `nextPage()` method returns a new paginator instance configured for the next page, or `null` when there are no more pages. Similarly, `previousPage()` returns a paginator for the previous page, or `null` when at the first page.
365+
The `nextPage()` method returns a new paginator instance configured for the next page, or `null` when there are no more pages.
366+
Similarly, `previousPage()` returns a paginator for the previous page, or `null` when at the first page.
369367

370368
## Writing data
371369

0 commit comments

Comments
 (0)