Add animation
This commit is contained in:
@@ -1,16 +1,19 @@
|
|||||||
import ComposableArchitecture
|
import ComposableArchitecture
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
extension Reducer {
|
extension Reducer {
|
||||||
public func subscribe<TriggerAction, StreamElement>(
|
public func subscribe<TriggerAction, StreamElement>(
|
||||||
to stream: @escaping () async -> AsyncStream<StreamElement>,
|
to stream: @escaping () async -> AsyncStream<StreamElement>,
|
||||||
on triggerAction: CaseKeyPath<Action, TriggerAction>,
|
on triggerAction: CaseKeyPath<Action, TriggerAction>,
|
||||||
with responseAction: CaseKeyPath<Action, StreamElement>
|
with responseAction: CaseKeyPath<Action, StreamElement>,
|
||||||
|
animation: Animation? = nil
|
||||||
) -> _SubscribeReducer<Self, TriggerAction, StreamElement, StreamElement> {
|
) -> _SubscribeReducer<Self, TriggerAction, StreamElement, StreamElement> {
|
||||||
.init(
|
.init(
|
||||||
parent: self,
|
parent: self,
|
||||||
on: triggerAction,
|
on: triggerAction,
|
||||||
to: stream,
|
to: stream,
|
||||||
with: responseAction,
|
with: responseAction,
|
||||||
|
animation: animation,
|
||||||
transform: { $0 }
|
transform: { $0 }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -19,6 +22,7 @@ extension Reducer {
|
|||||||
to stream: @escaping () async -> AsyncStream<StreamElement>,
|
to stream: @escaping () async -> AsyncStream<StreamElement>,
|
||||||
on triggerAction: CaseKeyPath<Action, TriggerAction>,
|
on triggerAction: CaseKeyPath<Action, TriggerAction>,
|
||||||
with responseAction: CaseKeyPath<Action, Value>,
|
with responseAction: CaseKeyPath<Action, Value>,
|
||||||
|
animation: Animation? = nil,
|
||||||
transform: @escaping (StreamElement) -> Value
|
transform: @escaping (StreamElement) -> Value
|
||||||
) -> _SubscribeReducer<Self, TriggerAction, StreamElement, Value> {
|
) -> _SubscribeReducer<Self, TriggerAction, StreamElement, Value> {
|
||||||
.init(
|
.init(
|
||||||
@@ -26,6 +30,7 @@ extension Reducer {
|
|||||||
on: triggerAction,
|
on: triggerAction,
|
||||||
to: stream,
|
to: stream,
|
||||||
with: responseAction,
|
with: responseAction,
|
||||||
|
animation: animation,
|
||||||
transform: transform
|
transform: transform
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -47,17 +52,22 @@ public struct _SubscribeReducer<Parent: Reducer, TriggerAction, StreamElement, V
|
|||||||
@usableFromInline
|
@usableFromInline
|
||||||
let transform: (StreamElement) -> Value
|
let transform: (StreamElement) -> Value
|
||||||
|
|
||||||
|
@usableFromInline
|
||||||
|
let animation: Animation?
|
||||||
|
|
||||||
init(
|
init(
|
||||||
parent: Parent,
|
parent: Parent,
|
||||||
on triggerAction: CaseKeyPath<Parent.Action, TriggerAction>,
|
on triggerAction: CaseKeyPath<Parent.Action, TriggerAction>,
|
||||||
to stream: @escaping () async -> AsyncStream<StreamElement>,
|
to stream: @escaping () async -> AsyncStream<StreamElement>,
|
||||||
with responseAction: CaseKeyPath<Parent.Action, Value>,
|
with responseAction: CaseKeyPath<Parent.Action, Value>,
|
||||||
|
animation: Animation?,
|
||||||
transform: @escaping (StreamElement) -> Value
|
transform: @escaping (StreamElement) -> Value
|
||||||
) {
|
) {
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.triggerAction = AnyCasePath(triggerAction)
|
self.triggerAction = AnyCasePath(triggerAction)
|
||||||
self.stream = stream
|
self.stream = stream
|
||||||
self.responseAction = AnyCasePath(responseAction)
|
self.responseAction = AnyCasePath(responseAction)
|
||||||
|
self.animation = animation
|
||||||
self.transform = transform
|
self.transform = transform
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +82,7 @@ public struct _SubscribeReducer<Parent: Reducer, TriggerAction, StreamElement, V
|
|||||||
effects,
|
effects,
|
||||||
.run { send in
|
.run { send in
|
||||||
for await value in await stream() {
|
for await value in await stream() {
|
||||||
await send(responseAction.embed(transform(value)))
|
await send(responseAction.embed(transform(value)), animation: animation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user