Latest | 0.2.6 |
---|---|
Homepage | https://github.com/intitni/NotReactive |
License | MIT |
Platforms | ios 9.0 |
Authors |
All those reactive libraries are cool, but they can be too complicated to do right.
Usage
Value
Value
initializes with a default value. On subscription, observers immediately receive the latest value.
let value = Value<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 = Value<Int>(0)
let disposable = value.observe()
.ignoreLatest()
.map { $0 }
.flatMap { anotherObservation }
.distinct()
.throttle(seconds: 0.5)
.on(DispatchQueue.main)
.filterNil()
.filter { $0 > 0 }
.withOldValue()
.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.6", "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.6" }, "social_media_url": "https://twitter.com/intitni", "platforms": { "ios": "9.0" }, "swift_versions": [ "5", "5" ], "source_files": "NotReactive/Classes/**/*", "swift_version": "5" }
Fri, 31 May 2019 10:11:34 +0000