File tree Expand file tree Collapse file tree 5 files changed +8
-10
lines changed Expand file tree Collapse file tree 5 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import UIKit
9
9
10
10
open class DataSource : NSObject {
11
11
private var cellRegister : Set < String > = Set ( )
12
- private var finalState : State = . init( )
12
+ internal var trueState : State = . init( )
13
13
public weak var collectionView : UICollectionView ?
14
14
15
15
public init ( collectionView: UICollectionView ) {
@@ -18,7 +18,7 @@ open class DataSource: NSObject {
18
18
19
19
public var state : State {
20
20
get {
21
- finalState
21
+ trueState
22
22
}
23
23
set {
24
24
reload ( newState: newValue)
@@ -34,7 +34,6 @@ open class DataSource: NSObject {
34
34
let request = Reloader . Request (
35
35
dataSource: self ,
36
36
collectionView: collectionView,
37
- oldState: finalState,
38
37
newState: newState,
39
38
isAnimated: isAnimated,
40
39
completion: completion ?? { _ in }
Original file line number Diff line number Diff line change @@ -14,10 +14,10 @@ public func forEach<Model: DiffAware>(
14
14
) -> State {
15
15
let onReload : Reloader . Reload = { request in
16
16
let reload : ( ) -> Void = {
17
- let oldModels : [ Model ] = request. oldState . models. compactMap ( { $0 as? Model } )
17
+ let oldModels : [ Model ] = request. dataSource . trueState . models. compactMap ( { $0 as? Model } )
18
18
19
19
if oldModels. isEmpty {
20
- request. dataSource. finalState = request. newState
20
+ request. dataSource. trueState = request. newState
21
21
request. collectionView. reloadData ( )
22
22
request. completion ( true )
23
23
return
@@ -28,7 +28,7 @@ public func forEach<Model: DiffAware>(
28
28
changes: changes,
29
29
section: 0 ,
30
30
updateData: {
31
- request. dataSource. finalState = request. newState
31
+ request. dataSource. trueState = request. newState
32
32
} ,
33
33
completion: request. completion
34
34
)
Original file line number Diff line number Diff line change @@ -14,11 +14,11 @@ public protocol ObserverOwner {
14
14
public struct Item < Cell: UICollectionViewCell > : ObserverOwner {
15
15
public let observer = Observer ( )
16
16
17
- public init ( _ closure: @escaping ( Cell ) -> Void ) {
17
+ public init ( _ closure: @escaping ( Context , Cell ) -> Void ) {
18
18
observer. onConfigure = { context, dataSource in
19
19
dataSource. registerIfNeeded ( collectionView: context. collectionView, cellType: Cell . self)
20
20
if let cell: Cell = context. collectionView. dequeue ( for: context. indexPath) {
21
- closure ( cell)
21
+ closure ( context , cell)
22
22
return cell
23
23
} else {
24
24
return nil
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ public struct Reloader {
11
11
public struct Request {
12
12
public let dataSource : DataSource
13
13
public let collectionView : UICollectionView
14
- public let oldState : State
15
14
public let newState : State
16
15
public let isAnimated : Bool
17
16
public let completion : Completion
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ final class MicroTests: XCTestCase {
30
30
]
31
31
32
32
dataSource. state = forEach ( models: persons) { person in
33
- Item < PersonCell > ( ) { cell in
33
+ Item < PersonCell > ( ) { context , cell in
34
34
cell. nameLabel. text = person. name
35
35
}
36
36
. onSelect { _ in
You can’t perform that action at this time.
0 commit comments