Skip to content

Commit c043a75

Browse files
committed
Clean up Store.ifLet (#754)
1 parent e74ea26 commit c043a75

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,16 @@ extension Store {
4848
then unwrap: @escaping (Store<Wrapped, Action>) -> Void,
4949
else: @escaping () -> Void = {}
5050
) -> Disposable where State == Wrapped? {
51-
let elseDisposable =
52-
self
53-
.producerScope(
54-
state: { state -> Effect<Wrapped?, Never> in
55-
state
56-
.skipRepeats { ($0 != nil) == ($1 != nil) }
51+
return self.producer.skipRepeats({ ($0 != nil) == ($1 != nil) })
52+
.startWithValues { state in
53+
if var state = state {
54+
unwrap(self.scope {
55+
state = $0 ?? state
56+
return state
57+
})
58+
} else {
59+
`else`()
5760
}
58-
)
59-
.startWithValues { store in
60-
if store.state == nil { `else`() }
6161
}
62-
63-
let unwrapDisposable =
64-
self
65-
.producerScope(
66-
state: { state -> Effect<Wrapped, Never> in
67-
state
68-
.skipRepeats { ($0 != nil) == ($1 != nil) }
69-
.compactMap { $0 }
70-
}
71-
)
72-
.startWithValues(unwrap)
73-
74-
return CompositeDisposable([elseDisposable, unwrapDisposable])
7562
}
7663
}

0 commit comments

Comments
 (0)