Skip to content

Commit c9ad719

Browse files
committed
add common decorations and transformations for base generators
1 parent a4a499d commit c9ad719

File tree

22 files changed

+257
-51
lines changed

22 files changed

+257
-51
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ extension CollectionContext: BuilderContext {
1414
public typealias ViewType = UICollectionViewCell
1515
public typealias GeneratorType = CollectionCellGenerator
1616

17-
// TODO: - add support for other types of generators or make (decorated generator)
18-
1917
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item: ConfigurableItem,
2018
Item: RegistrationTypeProvider {
2119
Item.rddm.collectionGenerator(with: model)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ public extension ConfigurableItem where Self: RegistrationTypeProvider {
1313
static func build<Context: BuilderContext>(in ctx: Context.Type, with model: Model) -> Context.GeneratorType {
1414
ctx.gen(Self.self, model: model)
1515
}
16-
16+
1717
}

Components/Sources/Table/Extensions/TableContext+TableWrappedCell.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ extension TableContext: BuilderContext {
1414
public typealias ViewType = UITableViewCell
1515
public typealias GeneratorType = TableCellGenerator
1616

17-
// TODO: - add support for other types of generators or make (decorated generator)
18-
1917
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item: ConfigurableItem,
2018
Item: RegistrationTypeProvider {
21-
Item.rddm.tableGenerator(with: model)
19+
Item.rddm.tableGenerator(with: model)
2220
}
2321

2422
public static func gen<Item>(_ type: Item.Type, model: Item.Model) -> GeneratorType where Item: ViewType,

Components/Sources/Table/Extensions/TableWrappedCell+RDDM.swift

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

1313
func tableGenerator(with model: Base.Model) -> BaseCellGenerator<TableWrappedCell<Base>> {
14-
TableWrappedCell<Base>.rddm.baseGenerator(with: model,
15-
and: .class)
14+
TableWrappedCell<Base>.rddm.baseGenerator(with: model, and: .class)
15+
}
16+
17+
}
18+
19+
public extension StaticDataDisplayWrapper where Base: UITableViewCell & ConfigurableItem & RegistrationTypeProvider {
20+
21+
func tableGenerator(with model: Base.Model) -> BaseCellGenerator<Base> {
22+
Base.rddm.baseGenerator(with: model, and: Base.prefferedRegistration)
1623
}
1724

1825
}

Example/ReactiveDataDisplayManager/Collection/CollectionViewController/CollectionViewController.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ private extension CollectionViewController {
6464
CollectionGenerators {
6565
titles.map { title -> CollectionCellGenerator in
6666
// Create generator
67-
let generator = TitleCollectionViewCell.rddm.calculatableHeightGenerator(with: title, referencedWidth: 100)
68-
generator.didSelectEvent += {
69-
debugPrint("\(title) selected")
70-
}
71-
generator.didDeselectEvent += {
72-
debugPrint("\(title) deselected")
73-
}
74-
return generator
67+
return TitleCollectionViewCell.rddm.calculatableHeightGenerator(with: title, referencedWidth: 100)
68+
.didSelectEvent {
69+
debugPrint("\(title) selected")
70+
}
71+
.didDeselectEvent {
72+
debugPrint("\(title) deselected")
73+
}
7574
}
7675
}
7776
}

Example/ReactiveDataDisplayManager/Collection/FoldableCollectionViewController/FoldableCollectionViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ private extension FoldableCollectionViewController {
8484
let folder3 = makeFoldableCellGenerator(color: .lightGray, expanded: true)
8585

8686
// Configure relationship
87-
folder3.childGenerators = child3
88-
folder2.childGenerators = child2 + [folder3]
89-
folder1.childGenerators = child1 + [folder2]
87+
folder3.children = child3
88+
folder2.children = child2 + [folder3]
89+
folder1.children = child1 + [folder2]
9090

9191
// Add foldable cell generators to adapter
9292
let visibleGenerators = getVisibleGenerators(for: folder1)
@@ -131,7 +131,7 @@ private extension FoldableCollectionViewController {
131131

132132
func getVisibleGenerators(for generator: CollectionCellGenerator) -> [CollectionCellGenerator] {
133133
if let foldableItem = generator as? CollectionFoldableItem, foldableItem.isExpanded {
134-
return foldableItem.childGenerators
134+
return foldableItem.children
135135
.map { getVisibleGenerators(for: $0) }
136136
.reduce([generator], +)
137137
} else {

Example/ReactiveDataDisplayManager/Stack/Landing/LandingStackViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private extension LandingStackViewController {
8080
alignment: .center,
8181
distribution: .fillEqually,
8282
spacing: 32),
83-
childGenerators: [mainButton, secondaryButton])
83+
children: [mainButton, secondaryButton])
8484

8585
// Add generators to adapter
8686
adapter += title

Example/ReactiveDataDisplayManager/Stack/Views/Generators/InnerStackCellGenerator.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ final class InnerStackCellGenerator: ViewGenerator {
2222
// MARK: - Properties
2323

2424
private let model: Model
25-
private let childGenerators: [ViewGenerator]
25+
private let children: [ViewGenerator]
2626

2727
// MARK: - Initialization
2828

29-
init(model: Model, childGenerators: [ViewGenerator]) {
29+
init(model: Model, children: [ViewGenerator]) {
3030
self.model = model
31-
self.childGenerators = childGenerators
31+
self.children = children
3232
}
3333

3434
}
@@ -47,7 +47,7 @@ extension InnerStackCellGenerator: ViewBuilder {
4747
let adapter = view.rddm.baseBuilder
4848
.build()
4949

50-
adapter += childGenerators
50+
adapter += children
5151

5252
adapter => .reload
5353
}

Example/ReactiveDataDisplayManager/Table/AllPluginsTableViewController/AllPluginsTableViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private extension AllPluginsTableViewController {
199199
let generator = FoldableTableViewCell.rddm.foldableGenerator(with: .init(title: "", isExpanded: false))
200200

201201
// Create and add child generators
202-
generator.childGenerators = Constants.titles.map { TitleTableViewCell.rddm.baseGenerator(with: $0) }
202+
generator.children = Constants.titles.map { TitleTableViewCell.rddm.baseGenerator(with: $0) }
203203

204204
// Add generator to adapter
205205
adapter += generator

Example/ReactiveDataDisplayManager/Table/FoldableTableViewController/FoldableTableViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private extension FoldableTableViewController {
8989
let generator = FoldableTableViewCell.rddm.foldableGenerator(with: .init(title: id, isExpanded: false))
9090

9191
// Create and add child generators
92-
generator.childGenerators = Constants.titleForSubcells.map { TitleTableViewCell.rddm.baseGenerator(with: $0) }
92+
generator.children = Constants.titleForSubcells.map { TitleTableViewCell.rddm.baseGenerator(with: $0) }
9393
return generator
9494
}
9595

0 commit comments

Comments
 (0)