You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Referencing for understanding #621
Instead of using the approach with .receive(on:) solution we would like to use the second approach to dismiss view controllers using ifLet. We use the coordinator pattern for managing view controller and navigation. The current ifLet does not allow us to get a reference to the vc to dismiss therefore we are thinking of doing something like below. However there is an issue since state is inaccessible due to internal protection. @stephencelis Would love your thoughts on this.
Is there a better solution to this?
store
.scope(state: { appState in
appState.optionalChildState
}, action: { action in
.optionalChildAction(action)
})
.ifLetVc(then: { [weak self] store in
let vc = ChildViewController(store: store)
self?.coordinator.present(vc: vc, animated: true, withNavigation: false)
return vc
}, else: { [weak self] vc in
self?.coordinator.dismiss(vc: vc, animated: true)
})
.store(in: &cancellables)
extension Store {
public func ifLetVc<Wrapped>(
then unwrap: @escaping (Store<Wrapped, Action>) -> UIViewController,
else: @escaping (UIViewController) -> Void
) -> Cancellable where State == Wrapped? {
var vc: UIViewController!
let elseCancellable =
self
.publisherScope(
state: { state in
state
.removeDuplicates(by: { ($0 != nil) == ($1 != nil) })
}
)
.sink { store in
if store.state.value == nil { `else`(vc) }
}
let unwrapCancellable =
self
.publisherScope(
state: { state in
state
.removeDuplicates(by: { ($0 != nil) == ($1 != nil) })
.compactMap { $0 }
}
)
.sink { store in
vc = unwrap(store)
}
return AnyCancellable {
elseCancellable.cancel()
unwrapCancellable.cancel()
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Referencing for understanding #621
Instead of using the approach with .receive(on:) solution we would like to use the second approach to dismiss view controllers using ifLet. We use the coordinator pattern for managing view controller and navigation. The current ifLet does not allow us to get a reference to the vc to dismiss therefore we are thinking of doing something like below. However there is an issue since state is inaccessible due to internal protection.
@stephencelis Would love your thoughts on this.
Is there a better solution to this?
Beta Was this translation helpful? Give feedback.
All reactions