Created
May 8, 2019 08:30
-
-
Save swift2931/6feeb0d10f6930590d8a0b0b8a2013f6 to your computer and use it in GitHub Desktop.
Tx
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
import UIKit | |
struct Rx<T> { | |
var tx: ((T) -> ())? | |
var val: T { | |
didSet { | |
tx?(val) | |
} | |
} | |
} | |
protocol ReTx: class { | |
func redux<T>(_ r: (Self, T) -> ()) -> (T) -> () | |
} | |
extension ReTx { | |
func redux<T>(_ r: @escaping (Self, T) -> ()) -> (T) -> () { | |
return { [weak self] t in | |
if let vc = self { | |
r(vc, t) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment