https://github.com/space-code/blade
Blade is a pagination framework that simplifies the integration of pagination into the application.
https://github.com/space-code/blade
composable-architecture pagination swift swiftui tca
Last synced: 7 months ago
JSON representation
Blade is a pagination framework that simplifies the integration of pagination into the application.
- Host: GitHub
- URL: https://github.com/space-code/blade
- Owner: space-code
- License: mit
- Created: 2024-01-15T09:10:25.000Z (about 2 years ago)
- Default Branch: dev
- Last Pushed: 2024-12-26T05:59:33.000Z (about 1 year ago)
- Last Synced: 2025-07-02T02:02:19.682Z (8 months ago)
- Topics: composable-architecture, pagination, swift, swiftui, tca
- Language: Swift
- Homepage:
- Size: 316 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README

blade
## Description
`Blade` is a pagination framework that simplifies the integration of pagination into the application.
- [Usage](#usage)
- [Requirements](#requirements)
- [Installation](#installation)
- [Communication](#communication)
- [Contributing](#contributing)
- [Author](#author)
- [License](#license)
## Usage
Blade provides two libraries for working with pagination: `Blade` and `BladeTCA`. `BladeTCA` is an extension designed for working with [Composable Architecture](https://github.com/pointfreeco/swift-composable-architecture). Both support working with offset and cursor-based paginations.
### Basic Usage
First, you need to implement page loader for whether cursor or offset based pagination:
```swift
import Blade
/// Offset pagination loader
final class OffsetPageLoader: IOffsetPageLoader {
func loadPage(request: OffsetPaginationRequest) async throws -> Page {
// Implementation here
}
}
/// Cursor pagination loader
final class CursorPageLoader: ICursorPageLoader {
func loadPage(request: CursorPaginationRequest) async throws -> Page {
// Implementation here
}
}
```
Second, create a `Paginator` instance:
```swift
import Blade
/// Offset-based pagination
let paginator = Paginator(configuration: PaginationLimitOffset(firstPage: .zero, limit: 20), offsetPageLoader: OffsetPageLoader())
/// Cursor-based pagination
let paginator = Paginator(configuration: PaginationCursorSeek(id: #id_here), offsetPageLoader: CursorPageLoader())
```
Third, the paginator is capable of requesting the first page, the next page, and resetting its state, like this:
```swift
/// Request an initial page
let page = try await paginator.refresh()
/// Request next page
let nextPage = try await paginator.nextPage()
/// Reset state
await paginator.reset()
```
### TCA Usage
If your app uses the [Composable Architecture](https://github.com/pointfreeco/swift-composable-architecture), `Blade` can be easily integrated.
```swift
import BladeTCA
// MARK: Reducer
@Reducer
struct SomeFeature {
// MARK: Types
struct State: Equatable {
var paginator: PaginatorState
}
enum Action {
case child(PaginatorAction)
}
// MARK: Reducer
var body: some ReducerOf {
Reduce { state, action in
switch state {
case .clild:
return .none
}
}
.paginator(
state: \SomeFeature.State.paginator,
action: /SomeFeature.Action.child,
loadPage: { request, state in
// Load page here
}
)
}
}
// MARK: View
import ComposableArchitecture
import SwiftUI
// MARK: - SomeView
struct SomeView: View {
// MARK: Properties
private let store: StoreOf
// MARK: Initialization
init(store: StoreOf) {
self.store = store
}
// MARK: View
var body: some View {
PaginatorListView(
store: store.scope(state: \.paginator, action: { .child($0) })
) { state in
// Implement UI here
}
}
```
## Requirements
- iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 7.0+ / visionOS 1.0+
- Xcode 15.0
- Swift 5.7
## Installation
### Swift Package Manager
The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but `blade` does support its use on supported platforms.
Once you have your Swift package set up, adding `blade` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
```swift
dependencies: [
.package(url: "https://github.com/space-code/blade.git", .upToNextMajor(from: "1.0.0"))
]
```
## Communication
- If you **found a bug**, open an issue.
- If you **have a feature request**, open an issue.
- If you **want to contribute**, submit a pull request.
## Contributing
Bootstrapping development environment
```
make bootstrap
```
Please feel free to help out with this project! If you see something that could be made better or want a new feature, open up an issue or send a Pull Request!
## Author
Nikita Vasilev, nv3212@gmail.com
## License
blade is available under the MIT license. See the LICENSE file for more info.