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

Introducing ReactKit

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Introducing ReactKit

Avatar for Yasuhiro Inami

Yasuhiro Inami

December 17, 2014
Tweet

More Decks by Yasuhiro Inami

Other Decks in Programming

Transcript

  1. Frameworks Yasuhiro Inami Ex-iOS Engineer #potatotips 2014-12-17 Session 203 ©

    2014 @inamiy, All rights reserved. Redistribution or public display not permitted without written permission from @inamiy. Introducing ReactKit
  2. Who are you? Yasuhiro Inami (@inamiy) LINE corp / NAVER

    Matome Ex-iOS / Java Server Engineer • Objective-C: 4 years, 26 repos • Java: 10 months, 0 repo • Swift: 6 months, 8 repos
  3. let signal = KVO.signal(obj1, "value") ! // REACT (obj2, "value")

    <~ signal ! XCTAssertEqual(obj1.value, "initial") XCTAssertEqual(obj2.value, "initial") ! obj1.value = "hoge" ! XCTAssertEqual(obj1.value, "hoge") XCTAssertEqual(obj2.value, "hoge") // reactive! Key-Value Observing/Coding
  4. self.signal = Notification.signal("MyNotification", obj1).map { notification -> NSString? in !

    return notification!.userInfo!["hoge"] as? NSString ! } ! // REACT (obj2, "value") <~ self.signal! NSNotification
  5. // UITextField self.textFieldSignal = self.textField?.textChangedSignal() ! (self.label, "text") <~ self.textFieldSignal!

    ! ! // UIButton self.buttonSignal = self.button?.buttonSignal { _ in return "OK" } ! (self.label, "text") <~ self.buttonSignal! Target-Action
  6. SwiftState Elegant state machine for Swift State & Event (Enum/String)

    based transition manager • Guard conditions • Wildcard state (AnyState) • Success/Error/Entry/Exit handlers with UInt8 order • Removable routes & handlers Easy Swift Syntax • Transition: .State0 => .State1 • Transition chaining: .State0 => .State1 => .State2 • Try transition: machine <- .State1 • Try transition + messaging: 
 machine <- (.State1, "GoGoGo") • Try event: machine <-! .Event1
  7. SwiftTask Promise + progress + pause + cancel + retry

    Future fulfilled/rejected value-pipelining with • progress • pause/resume • cancel • [New!] try (retryable) Pure Swift (for single task) Very thin wrapper around callback-hell objects Focused on pipelining only • no concurrency programming implemented • use whatever you want inside task-definition • e.g. GCD, NSThread, NSOperation, POSIX threads
  8. ReactKit Core code public class Signal<T>: Task<T, T, NSError> {

    public let name: String public init(name: String = "Default", initClosure: Task<T, T, NSError>.InitClosure) { self.name = name super.init(weakified: true, initClosure: initClosure) } }
  9. ReactKit Signal Operations // Signal Operations public extension Signal {

    public func filter(filterClosure: T -> Bool) -> Signal<T> public func map<U>(transform: T -> U) -> Signal<U> public func take(maxCount: Int) -> Signal public func take<U>(until signal: Signal<U>) -> Signal }
  10. ReactKit Signal Operations Instance Methods (ver 0.3.0) • filter(f: T

    -> Bool) • map(f: T -> U) • map(f: T -> Signal<U>) (a.k.a Rx.flatMap) • map(accumulate:accumulateClosure:) (a.k.a Rx.scan) • take(count) • take(until: Signal) • skip(count) • skip(until: Signal) • buffer(count) • buffer(trigger: Signal) • throttle(timeInterval) • debounce(timeInterval) Class Methods • any(signals)
  11. When to use … Now! Use cases • Networking •

    User interface binding • …and a lot Can replace if your code uses • ReactiveCocoa • PromiseKit • Bolts-iOS • FBKVOController • …and a lot
  12. When to use … Now! [New!] Carthage 0.3 compatible •

    echo 'github "ReactKit/ReactKit" ~> 0.3.0' >> Cartfile • carthage update (--use-submodules) • Drag & drop all frameworks to embed • Enjoy ~> iOS8 Contributors wanted! • Send me GitHub-issue or pull-request • or, please star
  13. More Information SwiftͰ༗ݶΦʔτϚτϯʢεςʔτϚγϯʣΛ࡞Δ - Qiita http://qiita.com/inamiy/items/cd218144c90926f9a134 ! Swiftʴ༗ݶΦʔτϚτϯͰPromiseΛ֦ு͢Δ - Qiita

    http://qiita.com/inamiy/items/d3579b55a3ecc28dde63 ! SwiftTaskʢPromise֦ுʣΛ࢖͏ - Qiita http://qiita.com/inamiy/items/0756339aee35849384c3 ! SwiftTask(Promise֦ு)ͰϦΞΫςΟϒϓϩάϥϛϯά - Qiita http://qiita.com/inamiy/items/d68cdb528b482ee0d8c1