From d3e310f91281f376930f72d6fdcadd66b3696707 Mon Sep 17 00:00:00 2001 From: Charles Maria Tor Date: Fri, 23 Jul 2021 13:13:06 +1000 Subject: [PATCH] Refactor dispatch function definition --- .../RecombinePackage/Store/BaseStore.swift | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Sources/RecombinePackage/Store/BaseStore.swift b/Sources/RecombinePackage/Store/BaseStore.swift index b5f0f4d..76dc278 100644 --- a/Sources/RecombinePackage/Store/BaseStore.swift +++ b/Sources/RecombinePackage/Store/BaseStore.swift @@ -152,22 +152,23 @@ public class BaseStore: StoreProtoco maxPublishers: maxPublishers, recurse(actions:) ) + let transformed: AnyPublisher<[RefinedAction], Never> if collect { - recursed + transformed = recursed .collect() .map { $0.flatMap { $0 } } - .sink { - self?._preMiddlewareRefinedActions.send($0) - } - .store(in: &cancellables) + .eraseToAnyPublisher() } else { - recursed - .sink { - self?._preMiddlewareRefinedActions.send($0) - } - .store(in: &cancellables) + transformed = recursed + .eraseToAnyPublisher() } + + transformed + .sink { + self?._preMiddlewareRefinedActions.send($0) + } + .store(in: &cancellables) } open func injectBypassingMiddleware(actions: S) where S.Element == RefinedAction {