Skip to content

Commit

Permalink
chore: wrapperToSingleTypeSection
Browse files Browse the repository at this point in the history
  • Loading branch information
linhey committed Nov 9, 2022
1 parent f8060c4 commit 096b4d8
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Example/Example/Home/DecorationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DecorationViewController: SKCollectionViewController {
extension DecorationViewController {
class LeftViewController: SKCollectionViewController {

let section = StringRawCell<Action>.singleTypeWrapper(Action.allCases)
let section = StringRawCell<Action>.wrapperToSingleTypeSection(Action.allCases)
lazy var skmanager = SKCManager(sectionView: sectionView)

override func viewDidLoad() {
Expand All @@ -84,7 +84,7 @@ extension DecorationViewController {

lazy var sections = (0 ... 10).map { sectionIndex in
ColorBlockCell
.singleTypeWrapper((0 ... 10).map { index in
.wrapperToSingleTypeSection((0 ... 10).map { index in
.init(color: .red, text: "\(sectionIndex - index)", size: size)
})
.set(supplementary: .init(kind: .header, type: ReusableView.self, model: "header - \(sectionIndex)"))
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/Home/PrefetchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
import StemColor

class PrefetchViewController: SKCollectionViewController {
private let section = ColorBlockCell.singleTypeWrapper()
private let section = ColorBlockCell.wrapperToSingleTypeSection()
private var cancellables = Set<AnyCancellable>()

override func viewDidLoad() {
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/Home/SingleTypeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension SingleTypeViewController {
class LeftViewController: SKCollectionViewController {

let section = StringRawCell
.singleTypeWrapper(builder: {
.wrapperToSingleTypeSection(builder: {
Action.allCases
})

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
``` swift
let model = FLSpacerCell.Model(size: .zero)
/// 以下 API 完全等价
let section1 = FLSpacerCell.singleTypeWrapper([model])
let section2 = FLSpacerCell.singleTypeWrapper(model)
let section1 = FLSpacerCell.wrapperToSingleTypeSection([model])
let section2 = FLSpacerCell.wrapperToSingleTypeSection(model)
let section3 = SKCSingleTypeSection<FLSpacerCell>([model])
let section4 = SKCSingleTypeSection<FLSpacerCell>(model)
```
Expand All @@ -110,8 +110,8 @@
``` swift
/// 创建 Section
let model = FLSpacerCell.Model(size: .zero)
let section1 = FLSpacerCell.singleTypeWrapper([model])
let section2 = FLCustomCell.singleTypeWrapper(model)
let section1 = FLSpacerCell.wrapperToSingleTypeSection([model])
let section2 = FLCustomCell.wrapperToSingleTypeSection(model)
/// manager 与 UICollectionView 关联
let sectionView = UICollectionView(frame: .zero,collectionViewLayout: UICollectionViewFlowLayout())
Expand All @@ -125,7 +125,7 @@

``` swift
let section = FLSpacerCell
.singleTypeWrapper([model])
.wrapperToSingleTypeSection([model])
/// 配置当前 section 样式
.setSectionStyle({ section in
Expand Down Expand Up @@ -184,7 +184,7 @@
> 修改数据后会刷新响应视图, 无需手动刷新

``` swift
let section = FLSpacerCell.singleTypeWrapper([model])
let section = FLSpacerCell.wrapperToSingleTypeSection([model])
/// 重置数据为 models
_ = section.config(models: [Model])
section.apply(models: [Model])
Expand All @@ -199,7 +199,7 @@
- 事件订阅

``` swift
let section = FLSpacerCell.singleTypeWrapper([model])
let section = FLSpacerCell.wrapperToSingleTypeSection([model])
section.pulishers.cellActionPulisher.sink { context in
switch context.type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@ import UIKit

public extension SKConfigurableView where Self: UICollectionViewCell & SKLoadViewProtocol {

static func singleTypeWrapper(@SectionArrayResultBuilder<Model> builder: () -> [Model]) -> SKCSingleTypeSection<Self> {
static func wrapperToSingleTypeSection(@SectionArrayResultBuilder<Model> builder: () -> [Model]) -> SKCSingleTypeSection<Self> {
.init(builder())
}

static func singleTypeWrapper(_ model: Model) -> SKCSingleTypeSection<Self> {
singleTypeWrapper([model])
static func wrapperToSingleTypeSection(_ model: Model) -> SKCSingleTypeSection<Self> {
wrapperToSingleTypeSection([model])
}

static func singleTypeWrapper(_ models: [Model]) -> SKCSingleTypeSection<Self> {
static func wrapperToSingleTypeSection(_ models: [Model]) -> SKCSingleTypeSection<Self> {
.init(models)
}

static func singleTypeWrapper() -> SKCSingleTypeSection<Self> {
singleTypeWrapper([] as [Model])
static func wrapperToSingleTypeSection() -> SKCSingleTypeSection<Self> {
wrapperToSingleTypeSection([] as [Model])
}

static func singleTypeWrapper(_ tasks: [() -> Self.Model]) -> SKCSingleTypeSection<Self> {
return singleTypeWrapper(tasks.map({ $0() }))
static func wrapperToSingleTypeSection(_ tasks: [() -> Self.Model]) -> SKCSingleTypeSection<Self> {
return wrapperToSingleTypeSection(tasks.map({ $0() }))
}

static func singleTypeWrapper(_ tasks: [() async throws -> Model]) async throws -> SKCSingleTypeSection<Self> {
static func wrapperToSingleTypeSection(_ tasks: [() async throws -> Model]) async throws -> SKCSingleTypeSection<Self> {
var models = [Model]()
for task in tasks {
models.append(try await task())
}
return singleTypeWrapper(models)
return wrapperToSingleTypeSection(models)
}

static func singleTypeWrapper(count: Int) -> SKCSingleTypeSection<Self> where Model == Void {
singleTypeWrapper(.init(repeating: (), count: count))
static func wrapperToSingleTypeSection(count: Int) -> SKCSingleTypeSection<Self> where Model == Void {
wrapperToSingleTypeSection(.init(repeating: (), count: count))
}

}
10 changes: 5 additions & 5 deletions Sources/SectionUI/Sections/SKCSectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public extension SKCSectionActionProtocol where Self: SKCDataSourceProtocol & SK
insets: UIEdgeInsets = .zero,
style: ((SKCollectionView) -> Void)? = nil) -> SKCSingleTypeSection<SKCSectionViewCell> {
SKCSectionViewCell
.singleTypeWrapper([.init(section: .normal([self]),
height: height,
insets: insets,
scrollDirection: .horizontal,
style: style)])
.wrapperToSingleTypeSection([.init(section: .normal([self]),
height: height,
insets: insets,
scrollDirection: .horizontal,
style: style)])

}

Expand Down
6 changes: 3 additions & 3 deletions Tests/SectionKitTests/SingleTypeEventsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import Combine
import SectionUI
import XCTest

final class SingleTypeWrapperTests: XCTestCase {
final class wrapperToSingleTypeSectionTests: XCTestCase {
func testCount() throws {
for count in 0 ... Int.random(in: 0 ... 1000) {
XCTAssert(SectionVoidCell.singleTypeWrapper(count: count).models.count == count)
XCTAssert(SectionVoidCell.wrapperToSingleTypeSection(count: count).models.count == count)
}
}

func testEvents() throws {
let section = SectionVoidCell.singleTypeWrapper(count: 3)
let section = SectionVoidCell.wrapperToSingleTypeSection(count: 3)
let view = SKCollectionView()
view.frame.size = .init(width: 400, height: 400)
view.manager.reload(section)
Expand Down
4 changes: 2 additions & 2 deletions Tests/SectionKitTests/SingleTypeWrapperBuilderTest.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SingleTypeWrapperBuilderTest.swift
// wrapperToSingleTypeSectionBuilderTest.swift
//
//
// Created by linhey on 2022/8/31.
Expand All @@ -8,7 +8,7 @@
import XCTest
import SectionKit

final class SingleTypeWrapperBuilderTest: XCTestCase {
final class wrapperToSingleTypeSectionBuilderTest: XCTestCase {

func builder(@SectionArrayResultBuilder<Int> builder: () -> [Int]) -> [Int] {
builder()
Expand Down

0 comments on commit 096b4d8

Please sign in to comment.