Upgrade to Pro — share decks privately, control downloads, hide ads and more …

migrating-from-promise-to-reactive

 migrating-from-promise-to-reactive

Gotanda.mobile #2 in VASILY (https://gotandamb.connpass.com/event/50876/)

horimislime

March 23, 2017
Tweet

More Decks by horimislime

Other Decks in Technology

Transcript

  1. Promise͔ΒReactive΁ͷҠߦΛ໛ࡧ͢Δ
    Gotanda.mobile #2
    @horimislime
    1

    View full-size slide

  2. self
    • @horimislime
    • גࣜձࣾτϨλ @ޒ൓ాTOC
    • ҿ৯ళ޲͚iPad୆ாΞϓϦΛ։ൃͯ͠·͢
    2

    View full-size slide

  3. ͓࿩
    • PromiseͰඇಉظϓϩάϥϛϯά͍ͯ͠Δ/͠Α͏ͱ͍ͯ͠Δਓ
    ʹ΋ReactiveΛΦεεϝ͢Δ࿩
    • ๭ࣾͷΞϓϦͰͷࣄྫΛఴ͑ͯ
    3

    View full-size slide

  4. Objective-Cࢿ࢈ͷ͋ΔΞϓϦ
    • BoltsFrameworkʹΑΔPromise
    • APIClient͕BoltsͷTaskΛฦ͢
    • ্Ґ૚Ͱ΋޿ൣғʹBoltsʹґଘ
    4

    View full-size slide

  5. ͦͯ͠SwiftҠߦظ΁
    • Bolts͸AnyObject͕ฦ͖ͬͯͯπϥ͍
    • SwiftyͳPromiseͷඞཁੑ
    • ͦͷޙ৭ʑ͋ͬͯҎԼʹґଘ͍ͯ͠Δ
    • Bolts-Objc
    • SwiftTask
    • Bolts-Swift
    5

    View full-size slide

  6. PromiseͰͷ՝୊ײ
    • ଟ͘ͷ΋ͷͰErrorͷܕࢦఆ͕Ͱ͖ͳ͍ࣄ΁ͷෆຬ
    • ϝϯςφϯε͕׆ൃͰͳ͍΋ͷ͕ग़͖ͯͭͭ͋Δ
    6

    View full-size slide

  7. enum AppError: Error {
    case offline
    case network
    }
    get(userId: 1234).then { user in
    ...
    }.catch { error in
    // !
    switch error as! AppError {
    ...
    }
    }
    7

    View full-size slide

  8. ɹɹɹ ݁Ռͷܕࢦఆ Errorͷܕࢦఆ Swift3
    Bolts-Swift ✅ ❌ ✅
    PromiseKit ✅ ❌ ✅
    SwiftTask ✅ ✅ ❌(branch༗)
    8

    View full-size slide

  9. Reactiveͷػӡ
    • SwiftҠߦͱڞʹSwiftBondΛ࢖͍࢝Ίͯͨ
    • ReactiveKitͱ͍͏฼ମʹґଘ
    • PromiseͰ΍Γ͍ͨࣄ͸େମͰ͖Δ
    9

    View full-size slide

  10. Promise෩ຯͳReactiveKit
    findPrinter()
    .flatMapLatesst { printer in
    return send(document, to: printer)
    }.flatMapLatest { result in
    return process(result)
    }.observe { event in
    switch event {
    case .completed: Progress.dismiss()
    case .failed(let error):
    switch error {
    case .network: Progress.showError("Network error!")
    ...
    }
    }
    }
    10

    View full-size slide

  11. ϝϦοτ
    • ͦΜͳʹҧ࿨ײ΋ͳ͍͠ɺbinding͚ͩͰͳ͘ඇಉظॲཧָ͕
    • طʹView bindingΛ࢖͍ͬͯΕ͹਌࿨ੑ˕
    • ௕ظతͳϝϯςφϯε΁ͷظ଴
    11

    View full-size slide

  12. ಋೖͷোน
    • Reactiveͷֶशίετ΁ͷݒ೦
    • ͜ͷ1೥͘Β͍ͰσϑΝΫτԽͨ͠ײ͕͋Δ
    • View Bindingʹ࢖͏ͳΒશମతʹReactiveԽͨ͠ํ͕౎߹
    ͕ྑ͍͜ͱ΋ଟ͍
    12

    View full-size slide

  13. ߟ͓͑ͯ͘΂͖ࣄ
    • Promise / Rxؔ࿈͸ෳ਺ϨΠϠͰ࢖༻͕ͪ͠
    • Լखʹબ୒͢Δͱ๲େͳҠߦίετͰࢮ͵
    • ࠷΋কདྷੑΛߟྀ͢Δ΂͖ॴ
    13

    View full-size slide

  14. ·ͱΊ
    • SwiftΛऔΓר͘Promiseࣄ৘
    • Reactiveͷোน͸ݮͬͯΔ͠ಋೖͷνϟϯε !
    • ٕͨͩ͠ज़બఆ͸৻ॏʹ
    14

    View full-size slide