Skip to content

Instantly share code, notes, and snippets.

View charlag's full-sized avatar

Willow charlag

View GitHub Profile
@charlag
charlag / RxInputs.kt
Last active May 21, 2017 10:39
Helper to reduce boilderplate when creating presenters / viewModels.
package com.charlag.rx.inputs
import rx.Observable
import rx.Subscription
import rx.subjects.PublishSubject
import rx.subscriptions.CompositeSubscription
import java.lang.reflect.InvocationHandler
import java.lang.reflect.Method
import java.lang.reflect.Proxy

Keybase proof

I hereby claim:

  • I am charlag on github.
  • I am charlag (https://keybase.io/charlag) on keybase.
  • I have a public key ASDCJQpk-E_YkHH9ltpAb2RTm9TKgTdwWl33Ohjb2VwNcQo

To claim this, I am signing this object:

@charlag
charlag / di.swift
Last active October 1, 2016 15:26
Dependency injection prototyping
protocol CatalogViewModelFactory {
func create(parameters: String) -> CatalogViewModel
}
struct CatalogViewModelFactoryImpl: CatalogViewModelFactory {
func create(parameters: String) -> CatalogViewModel {
return CatalogViewModelImpl(something: parameters,
productFactory: ProductViewModelFactoryImpl()) // should be resolved for this factory
enum LoginScreenState {
case ShowLogIn
case ShowSignUp
var buttonTitle: String {
switch self {
case .ShowLogIn:
return "Don't have an account?"
case .ShowSignUp:
return "Already have an account?"
dataSource.animationConfiguration = AnimationConfiguration(insertAnimation: .Fade,
reloadAnimation: .Fade,
deleteAnimation: .Fade)
screenState.asObservable()
.map { $0.cells }
.map { [AuthSection(model: 0, items: $0)] }
.bindTo(tableView.rx_itemsWithDataSource(dataSource))
.addDisposableTo(disposeBag)
footerButton.rx_tap
.asObservable()
.withLatestFrom(screenState.asObservable())
.map { state -> LoginScreenState in
switch state {
case .ShowLogIn:
return .ShowSignUp
case .ShowSignUp:
return .ShowLogIn
}
let screenState = Variable(LoginScreenState.ShowLogIn)
let footerButton = UIButton()
enum LoginScreenState {
case ShowLogIn
case ShowSignUp
var cells: [AuthCellType] {
switch self {
case .ShowLogIn:
return [
.Headline,
.Separator,
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
let disposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
tableView.estimatedRowHeight = 44