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 SwiftUI | |
import Combine | |
protocol Service { | |
static var mods: [String: (inout URLRequest) -> Void] {get set} | |
var baseURL: String {get set} | |
func config(_ pat: String, _ mod: @escaping (inout URLRequest) -> Void) | |
func decorated(_ absURL: String, _ req: URLRequest) -> URLRequest | |
func match(_ pat: String, _ absURL: String) -> Bool | |
func makeRequest(_ relativeURL: String) -> URLRequest |
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
// | |
// Redux.swift | |
// Elf | |
// | |
// Created by JimLai on 2019/8/18. | |
// Copyright © 2019 JimLai. All rights reserved. | |
// | |
import SwiftUI |
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
extension TypedContentAccessors { | |
var mj: MJ { | |
return MJ(entityForTypedContentAccessors?.content as Any) | |
} | |
} |
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) | |
} | |
} |
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 | |
protocol Redux: class { | |
func action<V> (_ action: @escaping (V, Self) -> ()) -> (V) -> () | |
} | |
extension Redux where Self: UIViewController { | |
func action<V> (_ action: @escaping (V, Self) -> ()) -> (V) -> () { | |
return { [weak self] v in | |
if let vc = self { | |
action(v, vc) |
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 | |
func dp(_ any: Any...) { | |
print(any) | |
} | |
protocol Redux: class { | |
func action(_ f: String) -> (Self) -> () | |
func effect(_ f: String) -> Self | |
func effect(_ desc: String, _ cls: () -> ()) -> Self |
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
iOS development builds around storyboard. | |
my opinionated approach is to keep only 1 view controller in each storyboard. | |
use it only as the view of controller, but do most of the control in code. | |
you may wonder why not just using XIB? | |
first it requires you overriding loadView(), which is some overhead |
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 Future<U> { | |
var u: U? { | |
didSet { | |
promise?(u) | |
} | |
} | |
var promise: ((U?) -> ())? | |
func then<V>(_ action: @escaping (U?, Future<V>) -> ()) -> Future<V> { |