Skip to content

Commit 6a0f777

Browse files
committed
add assotiated types to context to improve syntax
1 parent 5763b4d commit 6a0f777

File tree

41 files changed

+238
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+238
-87
lines changed

Components/Sources/Collection/Extensions/CollectionContext+CollectionWrappedCell.swift

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,34 @@ import UIKit
99
import Foundation
1010
import ReactiveDataDisplayManager
1111

12-
public extension CollectionContext {
12+
extension CollectionContext: BuilderContext {
1313

14-
static func stack(model: StackView.Model) -> CollectionCellGenerator {
14+
public typealias ViewType = UICollectionViewCell
15+
public typealias GeneratorType = CollectionCellGenerator
16+
17+
// TODO: - add support for other types of generators or make (decorated generator)
18+
19+
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item : ReactiveDataDisplayManager.ConfigurableItem, Item : ReactiveDataDisplayManager.RegistrationTypeProvider {
20+
Item.rddm.collectionGenerator(with: model, and: Item.prefferedRegistration)
21+
}
22+
23+
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item : ViewType, Item : ConfigurableItem, Item : RegistrationTypeProvider {
24+
Item.rddm.baseGenerator(with: model, and: Item.prefferedRegistration)
25+
}
26+
27+
public static func stack(model: StackView.Model) -> CollectionCellGenerator {
1528
StackView.rddm.collectionGenerator(with: model, and: .class)
1629
}
1730

18-
static func viewNib<T: UIView & ConfigurableItem>(type: T.Type,
19-
model: T.Model) -> BaseCollectionCellGenerator<CollectionWrappedCell<T>> {
31+
@available(*, deprecated, renamed: "gen", message: "Please use `gen` method and `RegistrationTypeProvider` instead")
32+
public static func viewNib<T: UIView & ConfigurableItem>(type: T.Type,
33+
model: T.Model) -> BaseCollectionCellGenerator<CollectionWrappedCell<T>> {
2034
T.rddm.collectionGenerator(with: model, and: .nib)
2135
}
2236

23-
static func viewClass<T: UIView & ConfigurableItem>(type: T.Type,
24-
model: T.Model) -> BaseCollectionCellGenerator<CollectionWrappedCell<T>> {
37+
@available(*, deprecated, renamed: "gen", message: "Please use `gen` method and `RegistrationTypeProvider` instead")
38+
public static func viewClass<T: UIView & ConfigurableItem>(type: T.Type,
39+
model: T.Model) -> BaseCollectionCellGenerator<CollectionWrappedCell<T>> {
2540
T.rddm.collectionGenerator(with: model, and: .class)
2641
}
2742

Components/Sources/Collection/Extensions/CollectionWrappedCell+RDDM.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import UIKit
1111
public extension StaticDataDisplayWrapper where Base: UIView & ConfigurableItem {
1212

1313
func collectionGenerator(with model: Base.Model,
14-
and registerType: CellRegisterType = .nib) -> BaseCollectionCellGenerator<CollectionWrappedCell<Base>> {
14+
and registerType: RegistrationType = .nib) -> BaseCollectionCellGenerator<CollectionWrappedCell<Base>> {
1515
CollectionWrappedCell<Base>.rddm.baseGenerator(with: model,
1616
and: registerType)
1717
}
@@ -25,7 +25,7 @@ public extension StaticDataDisplayWrapper where Base: UIView & ConfigurableItem
2525
func tableCalculatableHightGenerator(
2626
with model: Base.Model,
2727
width: CGFloat,
28-
and registerType: CellRegisterType = .nib
28+
and registerType: RegistrationType = .nib
2929
) -> CalculatableHeightCollectionCellGenerator<CollectionWrappedCell<Base>> {
3030

3131
CalculatableHeightCollectionCellGenerator<CollectionWrappedCell<Base>>(with: model,
@@ -42,7 +42,7 @@ public extension StaticDataDisplayWrapper where Base: UIView & ConfigurableItem
4242
func tableCalculatableWidthGenerator(
4343
with model: Base.Model,
4444
height: CGFloat,
45-
and registerType: CellRegisterType = .nib
45+
and registerType: RegistrationType = .nib
4646
) -> CalculatableWidthCollectionCellGenerator<CollectionWrappedCell<Base>> {
4747

4848
CalculatableWidthCollectionCellGenerator<CollectionWrappedCell<Base>>(with: model,

Components/Sources/Common/Extensions/ConfigurableItem+Builder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ReactiveDataDisplayManager
99

1010
public extension ConfigurableItem {
1111

12-
static func buildView(with model: Self.Model, and type: CellRegisterType = .nib) -> Self {
12+
static func buildView(with model: Self.Model, and type: RegistrationType = .nib) -> Self {
1313
let cell: Self?
1414
switch type {
1515
case .nib:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// ConfigurableItem+Context.swift
3+
// ReactiveDataDisplayManager
4+
//
5+
// Created by Никита Коробейников on 26.07.2023.
6+
//
7+
8+
import ReactiveDataDisplayManager
9+
10+
public extension ConfigurableItem {
11+
12+
static func build<T: BuilderContext>(in context: T.Type, with model: Self.Model) -> T.GeneratorType? {
13+
// TODO: - TBD
14+
return nil
15+
}
16+
17+
}

Components/Sources/Common/Extensions/ViewContext+Stack.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ReactiveDataDisplayManager
1111

1212
public extension ViewContext {
1313

14-
static func stack(model: StackView.Model) -> StackCellGenerator {
14+
static func stack(model: StackView.Model) -> ViewGenerator {
1515
StackView.rddm.viewGenerator(with: model, and: .class)
1616
}
1717

Components/Sources/Common/Views/LabelView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,11 @@ extension LabelView.Model {
222222
}
223223

224224
}
225+
226+
// MARK: - RegistrationTypeProvider
227+
228+
extension LabelView: RegistrationTypeProvider {
229+
230+
public static var prefferedRegistration: RegistrationType { .class }
231+
232+
}

Components/Sources/Common/Views/MessageView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,13 @@ extension MessageView.Model {
331331
}
332332
}
333333

334+
}
335+
336+
// MARK: - RegistrationTypeProvider
337+
338+
extension MessageView: RegistrationTypeProvider {
339+
340+
public static var prefferedRegistration: RegistrationType { .class }
341+
334342
}
335343
#endif

Components/Sources/Common/Views/SeparatorView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,11 @@ private extension SeparatorView {
8989
}
9090

9191
}
92+
93+
// MARK: - RegistrationTypeProvider
94+
95+
extension SeparatorView: RegistrationTypeProvider {
96+
97+
public static var prefferedRegistration: RegistrationType { .class }
98+
99+
}

Components/Sources/Common/Views/SpacerView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,11 @@ public extension SpacerWrapper where Model == SpacerView.Model {
109109
}
110110

111111
}
112+
113+
// MARK: - RegistrationTypeProvider
114+
115+
extension SpacerView: RegistrationTypeProvider {
116+
117+
public static var prefferedRegistration: RegistrationType { .class }
118+
119+
}

Components/Sources/Common/Views/StackView.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension StackView: ConfigurableItem {
4040
return closure(model)
4141
}
4242

43-
public static func children(_ value: [StackCellGenerator]) -> Property {
43+
public static func children(_ value: [ViewGenerator]) -> Property {
4444
.init(closure: { model in
4545
var model = model
4646
model.set(children: value)
@@ -49,7 +49,7 @@ extension StackView: ConfigurableItem {
4949
}
5050

5151
/// Only for stack. Cannot be included in common macros.
52-
public static func children(@GeneratorsBuilder<StackCellGenerator>_ content: @escaping (ViewContext.Type) -> [StackCellGenerator]) -> Property {
52+
public static func children(@GeneratorsBuilder<ViewGenerator>_ content: @escaping (ViewContext.Type) -> [ViewGenerator]) -> Property {
5353
.init(closure: { model in
5454
var model = model
5555
model.set(children: content(ViewContext.self))
@@ -85,7 +85,7 @@ extension StackView: ConfigurableItem {
8585

8686
// MARK: - Public properties
8787

88-
private(set) public var children: [StackCellGenerator] = []
88+
private(set) public var children: [ViewGenerator] = []
8989
private(set) public var style: StackStyle = .init(axis: .horizontal,
9090
spacing: 0,
9191
alignment: .fill,
@@ -95,7 +95,7 @@ extension StackView: ConfigurableItem {
9595

9696
// MARK: - Mutation
9797

98-
mutating func set(children: [StackCellGenerator]) {
98+
mutating func set(children: [ViewGenerator]) {
9999
self.children = children
100100
}
101101

@@ -165,3 +165,11 @@ private extension StackView {
165165
}
166166

167167
}
168+
169+
// MARK: - RegistrationTypeProvider
170+
171+
extension StackView: RegistrationTypeProvider {
172+
173+
public static var prefferedRegistration: RegistrationType { .class }
174+
175+
}

0 commit comments

Comments
 (0)