-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIKit binding internals refactoring (#10)
* simplified Presenter * minor API improvements * moved presenter * minor fix * simplified presenter * updated ref cycle test
- Loading branch information
1 parent
29f76cf
commit fcb9932
Showing
4 changed files
with
61 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,55 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// | ||
// Created by Sergey Kazakov on 02.12.2020. | ||
// | ||
|
||
|
||
|
||
import Dispatch | ||
|
||
public protocol PresenterProtocol { | ||
func subscribeToStore() | ||
} | ||
|
||
public protocol Presentable: AnyObject { | ||
associatedtype Props | ||
|
||
var presenter: PresenterProtocol? { get set } | ||
|
||
func setProps(_ props: Props) | ||
} | ||
|
||
public extension Presentable { | ||
|
||
func with<State, Action>(store: Store<State, Action>, | ||
props: @escaping (State, Store<State, Action>) -> Self.Props, | ||
presentationQueue: PresentationQueue = .sharedPresentationQueue, | ||
removeStateDuplicates equating: Equating<State> = .neverEqual) { | ||
|
||
let presenter = Presenter( | ||
viewController: self, | ||
store: store, | ||
props: props, | ||
presentationQueue: presentationQueue, | ||
removeStateDuplicates: equating.predicate) | ||
removeStateDuplicates equating: Equating<State>? = nil) { | ||
|
||
let weakStore = store.store() | ||
let observer = Observer( | ||
self, | ||
removeStateDuplicates: equating, | ||
observe: { [weak self] state, complete in | ||
presentationQueue.dispatchQueue.async { | ||
let props = props(state, weakStore) | ||
|
||
PresentationQueue.main.dispatchQueue.async { [weak self] in | ||
self?.setProps(props) | ||
complete(.active) | ||
} | ||
} | ||
} | ||
) | ||
|
||
presenter = Presenter { store.subscribe(observer: observer) } | ||
} | ||
} | ||
|
||
self.presenter = presenter | ||
struct Presenter: PresenterProtocol { | ||
let subscribe: () -> Void | ||
|
||
func subscribeToStore() { | ||
subscribe() | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,8 +100,4 @@ class ReferenceTypeState { | |
func reduce(_ action: Action) { | ||
|
||
} | ||
|
||
deinit { | ||
|
||
} | ||
} |
60 changes: 30 additions & 30 deletions
60
...s/PureduxTests/UIKitTests/ChildStorePresenterTests/ChildStorePresenterRefCycleTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters