Latest 0.2.2
Homepage https://github.com/intitni/NotReactive
License MIT
Platforms ios 9.3
Authors

CI Status
Version
License
Platform

All those reactive libraries are cool, but they can be too complicated to do right.

Usage

Observable

Observable initializes with a default value. On subscription, observers immediately receive the latest value.

let value = Observable<Int>(0)
let disposable = value.observe().subscribe { print($0) }
value.val = 1
// prints: 
// 0
// 1

Emitter

Emitter can send values or errors. Sending errors won’t terminate observations.

let emitter = Emitter<Int>()
let disposable = emitter.observe().subscribeEvent { print($0) }
emitter.emit(0)
emitter.emit(SomeError)
// prints:
// .next(0)
// .failure(SomeError)

KVO

let disposable = view.observe(.frame).subscribe { print($0) }

Notification

let disposable = NotificationCenter.default.observe(someNotification).subscribe { print($0) }

UIControl

let button = UIButton()
let disposable = button.observe(.touchUpInside).subscribe { print("tap") }
// prints: 
// tap

let textField = UITextField()
let disposable = textField.observe(.editingChanged, take: .text).subscribe { print($0) }
// prints:
// textField.text

Operators

let value = Observation<Int>(0)
let disposable = value.observe()
    .ignoreLatest()
    .map { $0 }
    .flatMap { anotherObservation }
    .distinct()
    .throttle(seconds: 0.5)
    .on(DispatchQueue.main)
    .filterNil()
    .filter { $0 > 0 }
    .subscribe { print($0) } // or bind(to:at:)

any(a.observe(), b.observe(), c.observe())
    .subscribe { print($0) }

Installation

NotReactive is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'NotReactive'

License

NotReactive is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "NotReactive",
    "version": "0.2.2",
    "summary": "A simple way to subscribe to value change or event emission.",
    "description": "A siiiimple way to subscribe to value change or event emission.",
    "homepage": "https://github.com/intitni/NotReactive",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "intitni": "[email protected]"
    },
    "source": {
        "git": "https://github.com/intitni/NotReactive.git",
        "tag": "0.2.2"
    },
    "social_media_url": "https://twitter.com/intitni",
    "platforms": {
        "ios": "9.3"
    },
    "swift_version": "4.2",
    "source_files": "NotReactive/Classes/**/*"
}

Pin It on Pinterest

Share This