RxEventHub
is an event hub in RxSwift
world, it makes multicasting event easy, type-safe and error-free, it's intent to replace usage of NSNotificationCenter
in most cases.
To make multicasting event type-safe and error-free, this lib provides RxEventProvider
with generic type. For each type of event you want to send and observe, you create a subclass of RxEventProvider
, just like below:
class ExampleIntEventProvider: RxEventProvider<Int>{}
This class is used to provide type info and event name. You may override the typeKey
method to provide custom event name.
You can notify the hub when events occur by simply writing 1 line code like below:
RxEventHub.sharedHub.notify(ExampleIntEventProvider(), data: 2)
You can get the Observable
(Observable<Int>
in this example) when events occur by simply writing 1 line code like below:
RxEventHub.sharedHub.eventObservable(ExampleIntEventProvider())
One more thing, you can either use the default hub RxEventHub.sharedHub
, or create different hubs for different modules as you want.
- Swift 3 (use 0.1.1 version for Swift 2)
RxEventHub is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "RxEventHub"
Just copy RxEventHub.swift
into your project, and you're ready to go.
RxEventHub is available under the MIT license. See the LICENSE file for more info.