From ea9efd8dd88130e913a3f4166e423d7ba8ffa10f Mon Sep 17 00:00:00 2001 From: marty-suzuki Date: Wed, 3 Apr 2019 16:19:51 +0900 Subject: [PATCH 1/4] retain logic in UnioStream --- Unio/UnioStream.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Unio/UnioStream.swift b/Unio/UnioStream.swift index d3adb95..e3e0a9b 100644 --- a/Unio/UnioStream.swift +++ b/Unio/UnioStream.swift @@ -14,7 +14,9 @@ open class UnioStream { private let state: StateType private let extra: ExtraType + private let logic: Logic + /// - note: initialize parameters are retained in UnioStream public init(input: Logic.Input, state: Logic.State, extra: Logic.Extra, logic: Logic) { let dependency = Dependency(input: input, state: state, extra: extra) let output = logic.bind(from: dependency) @@ -22,5 +24,6 @@ open class UnioStream { self.output = Relay(output) self.state = state self.extra = extra + self.logic = logic } } From ff08eeabe13cee176f3c6a7681902fd65fef7d37 Mon Sep 17 00:00:00 2001 From: marty-suzuki Date: Wed, 3 Apr 2019 16:32:49 +0900 Subject: [PATCH 2/4] update README --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d075bf1..8110a89 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,6 @@ The rule of Extra is having other dependencies of [UnioStream](#uniostream). ```swift struct Extra: ExtraType { let apiStream: GitHubSearchAPIStream() - let disposeBag = DisposeBag() } ``` @@ -144,6 +143,7 @@ struct Extra: ExtraType { The rule of Logic is generating [Output](#output) from Dependency. It generates [Output](#output) to call `func bind(from:)`. `func bind(from:)` is called once when [UnioStream](#uniostream) is initialized. +If you want to use DisposeBags in `func bind(from:)`, define properties of DisposeBag in Logic. ```swift struct Logic: LogicType { @@ -152,6 +152,8 @@ struct Logic: LogicType { typealias State = GitHubSearchViewStream.State typealias Extra = GitHubSearchViewStream.Extra + let disposeBag = DisposeBag() + func bind(from dependency: Dependency) -> Output } ``` @@ -169,7 +171,6 @@ Here is a exmaple of implementation. extension GitHubSearchViewStream.Logic { func bind(from dependency: Dependency) -> Output { - let disposeBag = dependency.extra.disposeBag let apiStream = dependency.extra.apiStream dependency.inputObservable(for: \.searchText) @@ -244,7 +245,6 @@ final class GitHubSearchViewStream: UnioStream, Gi struct Extra: ExtraType { let apiStream: GitHubSearchAPIStream() - let disposeBag = DisposeBag() } struct Logic: LogicType { @@ -252,13 +252,14 @@ final class GitHubSearchViewStream: UnioStream, Gi typealias Output = GitHubSearchViewStream.Output typealias State = GitHubSearchViewStream.State typealias Extra = GitHubSearchViewStream.Extra + + let disposeBag = DisposeBag() } } extension GitHubSearchViewStream.Logic { func bind(from dependency: Dependency) -> Output { - let disposeBag = dependency.extra.disposeBag let apiStream = dependency.extra.apiStream dependency.inputObservable(for: \.searchText) From befabfee836ccc75fa6aa1357eb0dfb4e958675b Mon Sep 17 00:00:00 2001 From: marty-suzuki Date: Wed, 3 Apr 2019 16:21:39 +0900 Subject: [PATCH 3/4] update template --- Example/UnioSample/GitHubSearchLogicStream.swift | 4 ++-- Example/UnioSample/GitHubSearchViewStream.swift | 3 ++- .../Mock___FILEBASENAME___Stream.swift | 4 ++-- .../Default/___FILEBASENAME___ViewController.swift | 4 ++-- .../Default/___FILEBASENAME___ViewStream.swift | 8 ++++---- .../UnioStream.xctemplate/___FILEBASENAME___Stream.swift | 8 ++++---- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Example/UnioSample/GitHubSearchLogicStream.swift b/Example/UnioSample/GitHubSearchLogicStream.swift index ac40c38..f1c6e2a 100644 --- a/Example/UnioSample/GitHubSearchLogicStream.swift +++ b/Example/UnioSample/GitHubSearchLogicStream.swift @@ -47,7 +47,6 @@ extension GitHubSearchLogicStream { let searchAPIStream: GitHubSearchAPIStreamType let scheduler: SchedulerType - let disposeBag = DisposeBag() } struct Logic: LogicType { @@ -55,6 +54,8 @@ extension GitHubSearchLogicStream { typealias Output = GitHubSearchLogicStream.Output typealias State = GitHubSearchLogicStream.State typealias Extra = GitHubSearchLogicStream.Extra + + let disposeBag = DisposeBag() } } @@ -64,7 +65,6 @@ extension GitHubSearchLogicStream.Logic { let state = dependency.state let extra = dependency.extra - let disposeBag = extra.disposeBag let searchAPIStream = extra.searchAPIStream searchAPIStream.output diff --git a/Example/UnioSample/GitHubSearchViewStream.swift b/Example/UnioSample/GitHubSearchViewStream.swift index c3888c7..1c5e33e 100644 --- a/Example/UnioSample/GitHubSearchViewStream.swift +++ b/Example/UnioSample/GitHubSearchViewStream.swift @@ -51,6 +51,8 @@ extension GitHubSearchViewStream { typealias Output = GitHubSearchViewStream.Output typealias State = GitHubSearchViewStream.State typealias Extra = GitHubSearchViewStream.Extra + + let disposeBag = DisposeBag() } } @@ -58,7 +60,6 @@ extension GitHubSearchViewStream.Logic { func bind(from dependency: Dependency) -> Output { - let disposeBag = dependency.extra.disposeBag let logicStream = dependency.extra.logicStream dependency.inputObservable(for: \.searchText) diff --git a/Tools/Mock UnioStream.xctemplate/Mock___FILEBASENAME___Stream.swift b/Tools/Mock UnioStream.xctemplate/Mock___FILEBASENAME___Stream.swift index faf02a8..ed0619b 100644 --- a/Tools/Mock UnioStream.xctemplate/Mock___FILEBASENAME___Stream.swift +++ b/Tools/Mock UnioStream.xctemplate/Mock___FILEBASENAME___Stream.swift @@ -1,8 +1,8 @@ //___FILEHEADER___ -import Unio -import RxSwift import RxCocoa +import RxSwift +import Unio final class Mock___VARIABLE_productName___Stream: ___VARIABLE_productName___StreamType { diff --git a/Tools/Unio Components.xctemplate/Default/___FILEBASENAME___ViewController.swift b/Tools/Unio Components.xctemplate/Default/___FILEBASENAME___ViewController.swift index 217e44a..0141789 100644 --- a/Tools/Unio Components.xctemplate/Default/___FILEBASENAME___ViewController.swift +++ b/Tools/Unio Components.xctemplate/Default/___FILEBASENAME___ViewController.swift @@ -1,8 +1,8 @@ //___FILEHEADER___ -import Unio -import UIKit import RxSwift +import UIKit +import Unio final class ___VARIABLE_productName___ViewController: UIViewController { diff --git a/Tools/Unio Components.xctemplate/Default/___FILEBASENAME___ViewStream.swift b/Tools/Unio Components.xctemplate/Default/___FILEBASENAME___ViewStream.swift index a77eb2a..607f5e1 100644 --- a/Tools/Unio Components.xctemplate/Default/___FILEBASENAME___ViewStream.swift +++ b/Tools/Unio Components.xctemplate/Default/___FILEBASENAME___ViewStream.swift @@ -1,8 +1,8 @@ //___FILEHEADER___ -import Unio -import RxSwift import RxCocoa +import RxSwift +import Unio protocol ___VARIABLE_productName___ViewStreamType: AnyObject { var input: Relay<___VARIABLE_productName___ViewStream.Input> { get } @@ -51,7 +51,6 @@ extension ___VARIABLE_productName___ViewStream { struct Extra: ExtraType { - let disposeBag = DisposeBag() } struct Logic: LogicType { @@ -59,6 +58,8 @@ extension ___VARIABLE_productName___ViewStream { typealias Output = ___VARIABLE_productName___ViewStream.Output typealias State = ___VARIABLE_productName___ViewStream.State typealias Extra = ___VARIABLE_productName___ViewStream.Extra + + let disposeBag = DisposeBag() } } @@ -67,7 +68,6 @@ extension ___VARIABLE_productName___ViewStream.Logic { func bind(from dependency: Dependency) -> Output { let state = dependency.state - let disposeBag = dependency.extra.disposeBag /* * EXAMPLE: diff --git a/Tools/UnioStream.xctemplate/___FILEBASENAME___Stream.swift b/Tools/UnioStream.xctemplate/___FILEBASENAME___Stream.swift index 10d8396..31052ea 100644 --- a/Tools/UnioStream.xctemplate/___FILEBASENAME___Stream.swift +++ b/Tools/UnioStream.xctemplate/___FILEBASENAME___Stream.swift @@ -1,8 +1,8 @@ //___FILEHEADER___ -import Unio -import RxSwift import RxCocoa +import RxSwift +import Unio protocol ___VARIABLE_productName___StreamType: AnyObject { var input: Relay<___VARIABLE_productName___Stream.Input> { get } @@ -51,7 +51,6 @@ extension ___VARIABLE_productName___Stream { struct Extra: ExtraType { - let disposeBag = DisposeBag() } struct Logic: LogicType { @@ -59,6 +58,8 @@ extension ___VARIABLE_productName___Stream { typealias Output = ___VARIABLE_productName___Stream.Output typealias State = ___VARIABLE_productName___Stream.State typealias Extra = ___VARIABLE_productName___Stream.Extra + + let disposeBag = DisposeBag() } } @@ -67,7 +68,6 @@ extension ___VARIABLE_productName___Stream.Logic { func bind(from dependency: Dependency) -> Output { let state = dependency.state - let disposeBag = dependency.extra.disposeBag /* * EXAMPLE: From 7bd40de3133928c67c0d3aad93925d7749ef89b6 Mon Sep 17 00:00:00 2001 From: marty-suzuki Date: Wed, 3 Apr 2019 16:45:41 +0900 Subject: [PATCH 4/4] update podspec --- Unio.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Unio.podspec b/Unio.podspec index 5cc1a5f..82e5bf8 100644 --- a/Unio.podspec +++ b/Unio.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "Unio" - s.version = "0.2.0" + s.version = "0.3.0" s.summary = "KeyPath based Unidirectionarl Input / Output framework with RxSwift." s.homepage = "https://github.com/cats-oss/Unio" s.license = { :type => "MIT", :file => "LICENSE" }