我想用 Firestore(Firesnapshot 和 Resiwft)对我的查询进行分页。正如谷歌文档中描述的那样,我只是找不到方法或无法做到这一点。
case updatePosts(userID: String, posts: [Snapshot<Model.Post>])
case updateListener(userID: String, listener: ListenerRegistration?)
static func subscribe(userID: String) -> AppThunkAction {
AppThunkAction { dispatch, _ in
let listener = Snapshot<Model.Post>.listen(.posts(userID: userID), queryBuilderBlock: { snapshot in
snapshot.order(by: .createTime, descending: true)
.where(\.isRemoved == false)
.limit(to: 3)
}) { result in
switch result {
case let .success(posts):
dispatch(FollowingPostsAction.updatePosts(userID: userID, posts: posts))
case let .failure(error):
print(error)
// error handling
dispatch(FollowingPostsAction.updatePosts(userID: userID, posts: []))
}
}
dispatch(FollowingPostsAction.updateListener(userID: userID, listener: listener))
}
}