-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from cats-oss/add-workaround
Add workaround for SR-12081
- Loading branch information
Showing
11 changed files
with
6,229 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Unio 0.9.0 Migration Guide | ||
|
||
Unio 0.9.0 introduces some breaking changes. | ||
|
||
Those changes are related [SR-12081](https://bugs.swift.org/browse/SR-12081). | ||
|
||
## Classes | ||
|
||
- [ADD] `AnyLogicBasedStream<Input: InputType, Output: OutputType>` | ||
|
||
## Typealias | ||
|
||
- [REPLACE] `typealias UnioStream<Logic: LogicType> = PrimitiveStream<Logic> & LogicType` -> `typealias UnioStream<Logic: LogicType> = AnyLogicBasedStream<Logic.Input, Logic.Output> & LogicType` | ||
|
||
## Note | ||
|
||
- Previous `UnioStream<Logic: LogicType>` (less than 0.8.0) had `init(input: Input, state: State, extra: Extra)` as the designated initializer. Current `UnioStream<Logic: LogicType>` (greater than 0.9.0) also has `init(input: Input, state: State, extra: Extra)` but it is the convenience initializer. So, you should fix initializers like that. | ||
|
||
Before | ||
```swift | ||
init(extra: Extra) { | ||
super.init(input: Input(), state: State(), extra: extra) | ||
} | ||
``` | ||
|
||
After | ||
```swift | ||
convenience init(extra: Extra) { | ||
self.init(input: Input(), state: State(), extra: extra) | ||
} | ||
``` | ||
|
||
If you defined some properties in UnioStream subclasses, you must change initializers to like that. | ||
|
||
Before | ||
```swift | ||
class NumberStream: UnioStream<NumberStream> { | ||
let number: Int | ||
|
||
init(number: Int, extra: Extra) { | ||
self.number = number | ||
super.init(input: Input(), state: State(), extra: extra) | ||
} | ||
} | ||
``` | ||
|
||
After | ||
```swift | ||
class NumberStream: UnioStream<NumberStream> { | ||
let number: Int | ||
|
||
init(number: Int, extra: Extra) { | ||
self.number = number | ||
super.init(input: Input(), state: State(), extra: extra, logic: NumberStream.self) | ||
} | ||
|
||
@available(*, unavailable) | ||
init<Logic: LogicType>(input: Logic.Input, | ||
state: Logic.State, | ||
extra: Logic.Extra, | ||
logic _: Logic.Type) where Input == Logic.Input, Output == Logic.Output { | ||
fatalError("could not be called anymore") | ||
} | ||
} | ||
``` | ||
|
||
- If you want to use existing UnioStream initializer (less than 0.8.0), please define `typealise UnioSteram<Logic: LogicType> = SR12081.UnioSteram<Logic>` in your Application Target. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// AnyLogicBasedStream.swift | ||
// Unio | ||
// | ||
// Created by marty-suzuki on 2020/01/25. | ||
// Copyright 漏 2020 tv.abema. All rights reserved. | ||
// | ||
|
||
/// Makes possible to implement Unidirectional input / output stream and be able to implement LogicType to its self. | ||
/// | ||
/// ``` | ||
/// // Usage Example | ||
/// class GithubSearchStream: UnioStream<GithubSearchStream> { | ||
/// struct Input: InputType {} | ||
/// | ||
/// struct Output: OutputType {} | ||
/// | ||
/// struct State: StateType {} | ||
/// | ||
/// struct Extra: ExtraType {} | ||
/// | ||
/// convenience init() { | ||
/// self.init(input: Input(), state: State(), extra: Extra()) | ||
/// } | ||
/// | ||
/// static func bind(from dependency: Dependency<Input, State, Extra>, disposeBag: DisposeBag) -> Output { | ||
/// return Output() | ||
/// } | ||
/// } | ||
/// ``` | ||
public typealias UnioStream<Logic: LogicType> = AnyLogicBasedStream<Logic.Input, Logic.Output> & LogicType | ||
|
||
/// A type which have LogicType based initializer. | ||
public protocol AnyLogicBasedStreamType: UnioStreamType { | ||
init<Logic: LogicType>(input: Logic.Input, | ||
state: Logic.State, | ||
extra: Logic.Extra, | ||
logic _: Logic.Type) where Input == Logic.Input, Output == Logic.Output | ||
} | ||
|
||
extension AnyLogicBasedStreamType where Self: LogicType { | ||
public init(input: Input, state: State, extra: Extra) { | ||
self.init(input: input, state: state, extra: extra, logic: Self.self) | ||
} | ||
} | ||
|
||
/// A type-erased wrapper which have LogicType based initializer. | ||
open class AnyLogicBasedStream<Input: InputType, Output: OutputType>: AnyLogicBasedStreamType { | ||
public let input: InputWrapper<Input> | ||
public let output: OutputWrapper<Output> | ||
|
||
/// Strong reference to the actual stream for preventing it being released. | ||
private let _stream: AnyObject | ||
|
||
required public init<Logic: LogicType>(input: Logic.Input, | ||
state: Logic.State, | ||
extra: Logic.Extra, | ||
logic _: Logic.Type) where Input == Logic.Input, Output == Logic.Output { | ||
let stream = PrimitiveStream<Logic>(input: input, state: state, extra: extra) | ||
self.input = stream.input | ||
self.output = stream.output | ||
self._stream = stream | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.