Skip to content

Instantly share code, notes, and snippets.

@swift2931
Created May 8, 2019 08:30
Show Gist options
  • Save swift2931/6feeb0d10f6930590d8a0b0b8a2013f6 to your computer and use it in GitHub Desktop.
Save swift2931/6feeb0d10f6930590d8a0b0b8a2013f6 to your computer and use it in GitHub Desktop.
Tx
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