Skip to content

Conversation

@jkmassel
Copy link
Contributor

@jkmassel jkmassel commented Nov 13, 2024

Builds on #380 by adding Combine and AsyncSequence-based pagination.

You can try it out by running the sample app and loading posts for https://content-heavy.wpmt.co – you'll see the posts slowly load in as they're paginated (the code has the page size set to 5 so it's easier to see).

I put the Combine stuff in its own module so that it doesn't have to be loaded (for instance, it'd be annoying for Linux environments).

Depends on #386 to build properly on Linux because Swift 6 brings unified Foundation.

@jkmassel jkmassel force-pushed the add/swift-async-pagination branch 2 times, most recently from cae5ecc to ff8e42b Compare November 13, 2024 06:30
Base automatically changed from add/swift-pagination to trunk November 13, 2024 23:11
@jkmassel jkmassel force-pushed the add/swift-async-pagination branch 3 times, most recently from 3753ee3 to 11a7334 Compare November 14, 2024 00:03
@jkmassel jkmassel self-assigned this Nov 14, 2024
@jkmassel jkmassel added the Swift label Nov 14, 2024
@jkmassel jkmassel marked this pull request as ready for review November 14, 2024 00:54
@jkmassel jkmassel force-pushed the add/swift-async-pagination branch 7 times, most recently from 7bf8014 to adf6d80 Compare November 14, 2024 05:58
@jkmassel jkmassel mentioned this pull request Nov 14, 2024
@jkmassel jkmassel force-pushed the add/swift-async-pagination branch from 7ce1005 to 865129d Compare November 14, 2024 06:26
public init(params: ResponseType.ParamsType, transform: @escaping Transformer) {
self.params = params
self.transform = transform
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably better to not make this initializer (and the Transformer) public, since it makes sense that only this library can create PaginationSequence instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in d597868

publisher.send(completion: .failure(error))
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The fact that the publisher doesn't emit elements unless fetch is called doesn't follow combine's programming model.

I don't think we really need this combine library/target, because it doesn't really relate to WordPressAPI. Its core is more like a generic solution of wrapping AsyncSequence in Publisher.

Copy link
Contributor Author

@jkmassel jkmassel Nov 14, 2024

Choose a reason for hiding this comment

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

Yeah, agreed – we'll need some support for this on the Rust side, so I've removed it for now in ba6ba90

@jkmassel jkmassel force-pushed the add/swift-async-pagination branch from 3c4aa13 to 1900424 Compare November 14, 2024 20:44
@jkmassel jkmassel force-pushed the add/swift-async-pagination branch from 1900424 to d597868 Compare November 14, 2024 20:49
@jkmassel jkmassel requested a review from crazytonyli November 14, 2024 21:25
@jkmassel jkmassel enabled auto-merge (squash) November 14, 2024 21:25
}

public struct PaginationSequence<ResponseType: PaginatableResponse>: AsyncSequence {
public typealias Transformer = (ResponseType.ParamsType) async throws -> ResponseType
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this public too?

}
}

struct ListViewSequence: AsyncSequence {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this struct implementation equavilant of asyncSequence.compactMap({ ($0 as? [ListViewDataConvertable]).asListViewData() })?

@jkmassel jkmassel merged commit 82fc7e3 into trunk Nov 14, 2024
22 checks passed
@jkmassel jkmassel deleted the add/swift-async-pagination branch November 14, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants