@@ -52,10 +52,19 @@ public final class Action<Input, Element> {
5252
5353 private let disposeBag = DisposeBag ( )
5454
55+ public convenience init < O: ObservableConvertibleType > (
56+ enabledIf: Observable < Bool > = Observable . just ( true ) ,
57+ workFactory: @escaping ( Input ) -> O
58+ ) where O. E == Element {
59+ self . init ( enabledIf: enabledIf) {
60+ workFactory ( $0) . asObservable ( )
61+ }
62+ }
63+
5564 public init (
5665 enabledIf: Observable < Bool > = Observable . just ( true ) ,
5766 workFactory: @escaping WorkFactory ) {
58-
67+
5968 self . _enabledIf = enabledIf
6069 self . workFactory = workFactory
6170
@@ -64,7 +73,7 @@ public final class Action<Input, Element> {
6473
6574 let errorsSubject = PublishSubject < ActionError > ( )
6675 errors = errorsSubject. asObservable ( )
67-
76+
6877 executionObservables = inputs
6978 . withLatestFrom ( enabled) { input, enabled in ( input, enabled) }
7079 . flatMap { input, enabled -> Observable < Observable < Element > > in
@@ -108,10 +117,10 @@ public final class Action<Input, Element> {
108117 }
109118
110119 let subject = ReplaySubject< Element> . createUnbounded( )
111-
120+
112121 let work = executionObservables
113122 . map { $0. catchError { throw ActionError . underlyingError ( $0) } }
114-
123+
115124 let error = errors
116125 . map { Observable< Element> . error( $0) }
117126
@@ -120,7 +129,7 @@ public final class Action<Input, Element> {
120129 . flatMap { $0 }
121130 . subscribe ( subject)
122131 . disposed ( by: disposeBag)
123-
132+
124133 return subject. asObservable ( )
125134 }
126135}
0 commit comments