This file contains hidden or 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
#!/bin/sh | |
echo "Running pre-commit..." | |
# pre-commit自体が最新かどうかをチェック | |
PRECOMMIT_MASTER_FILE='./script/pre-commit' | |
if [ -e $PRECOMMIT_MASTER_FILE ]; then | |
diff -s $PRECOMMIT_MASTER_FILE ./.git/hooks/pre-commit > /dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
cp $PRECOMMIT_MASTER_FILE ./.git/hooks/pre-commit |
This file contains hidden or 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
enum CachableRequestState { | |
/// 読み込み前 | |
case possible | |
/// 読込中 | |
case loading | |
/// 直近のリクエストがエラー | |
case error(Error) | |
This file contains hidden or 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
// | |
// CachableRequest.swift | |
// LIPS | |
// | |
import Foundation | |
import RxSwift | |
import RxCocoa | |
private extension ObservableType { |
This file contains hidden or 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
final class LazyBehaviorRelay<Element>: ObservableType, ObserverType { | |
private let _behaviorRelay = BehaviorRelay<Element?>(value: nil) | |
private let _emittedValue: Observable<Element> | |
init() { | |
_emittedValue = _behaviorRelay | |
.filterNil() | |
.share(replay: 1, scope: .forever) | |
} | |
This file contains hidden or 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
/// リクエストをして、データをキャッシュする | |
/// ロード中mの再呼び出しは無視する | |
/// これだと、一回データ取得して、二回目でエラー、みたいなときにつらい | |
class Repository<T> { | |
typealias State = RepositoryState<T, Error> | |
private let _request: Observable<T> | |
let state = BehaviorRelay<State>(value: .possible) | |
This file contains hidden or 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
extension CGRect { | |
/// 線形補間した矩形を返す | |
/// - parameter rate: 変化割合。0 <= rate <= 1の範囲で指定する。 | |
func lerp(to rect: CGRect, rate: CGFloat) -> CGRect { | |
let lerp = _lerpCurried(rate) | |
return CGRect( | |
x: lerp(origin.x, rect.origin.x), | |
y: lerp(origin.y, rect.origin.y), | |
width: lerp(width, rect.width), | |
height: lerp(height, rect.height) |
This file contains hidden or 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
/// delegateなどを配列などに持ちたいときに使う | |
private final class WeakObject<T: AnyObject> { | |
weak var object: T? | |
init(_ object: T?) { | |
self.object = object | |
} | |
} | |
final class PageViewControllerDelegateMulticaster: NSObject, UIPageViewControllerDelegate { |
This file contains hidden or 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
final class CircleImageRenderer { | |
let image: Observable<UIImage> | |
init(radius: CGFloat, fillColor: UIColor = .white) { | |
self.image = Observable.create { observer in | |
let format = UIGraphicsImageRendererFormat.default() | |
format.scale = UIScreen.main.scale | |
let width = radius * 2 | |
let size = CGSize.square(width) | |
let renderer = UIGraphicsImageRenderer( |
This file contains hidden or 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
func const<T, U>(_ value: T) -> (U) -> T { | |
return { _ in value } | |
} | |
func identity<T>() -> (T) -> T { | |
return { $0 } | |
} |
This file contains hidden or 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
// | |
// WithBlockingView.swift | |
// | |
extension ObservableConvertibleType { | |
/// actionがcompleteするまで画面を表示する | |
func withBlockingView(from parentViewController: UIViewController) -> Observable<Element> { | |
let viewController = _BlockingLoadingViewController(self) | |
return viewController.result | |
.do(onSubscribed: { [weak parentViewController] in |