Skip to content

Commit d1b8dc4

Browse files
committedJul 29, 2021
Change replay function type
1 parent 52a90c1 commit d1b8dc4

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed
 

‎Sources/RecombinePackage/Store/BaseStore.swift

+10-24
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ public class BaseStore<State: Equatable, RawAction, RefinedAction>: StoreProtoco
188188
)
189189
}
190190

191-
open func _replay<S: Sequence>(_ values: S) where S.Element == (offset: Double, actions: [RefinedAction]) {
191+
open func replay<S: Sequence>(_ values: S) where S.Element == (offset: Double, actions: [RefinedAction]) {
192+
dispatchEnabled = false
192193
values
193194
.publisher
194195
.flatMap { offset, actions in
@@ -197,30 +198,15 @@ public class BaseStore<State: Equatable, RawAction, RefinedAction>: StoreProtoco
197198
scheduler: DispatchQueue.global()
198199
)
199200
}
200-
201-
values.dropLast()
202-
.publisher
203-
}
204-
205-
open func replay<S: Sequence>(_ values: S) -> AnyPublisher<[RefinedAction], Never>
206-
where S.Element == (offset: Double, actions: [RefinedAction])
207-
{
208-
values
209-
.publisher
210-
.flatMap { offset, actions in
211-
Just(actions).delay(
212-
for: .seconds(max(0, offset)),
213-
scheduler: DispatchQueue.global()
214-
)
215-
}
216-
.handleEvents(
217-
receiveSubscription: { _ in self.dispatchEnabled = false },
218-
receiveOutput: _postMiddlewareRefinedActions.send,
219-
receiveCompletion: { _ in self.dispatchEnabled = true },
220-
receiveCancel: { self.dispatchEnabled = true }
221-
)
222201
// Cancel if dispatch is manually reenabled.
223202
.prefix(untilOutputFrom: $dispatchEnabled.filter { $0 })
224-
.eraseToAnyPublisher()
203+
.print("REPLAY::")
204+
.sink(
205+
receiveCompletion: { _ in
206+
self.dispatchEnabled = true
207+
},
208+
receiveValue: _postMiddlewareRefinedActions.send
209+
)
210+
.store(in: &cancellables)
225211
}
226212
}

0 commit comments

Comments
 (0)
Please sign in to comment.