|
1 | 1 | # RxEventHub
|
2 | 2 |
|
3 |
| -[](https://travis-ci.org/Chen Shenghan/RxEventHub) |
| 3 | +[](https://travis-ci.org/zzdjk6/RxEventHub) |
4 | 4 | [](http://cocoapods.org/pods/RxEventHub)
|
5 | 5 | [](http://cocoapods.org/pods/RxEventHub)
|
6 | 6 | [](http://cocoapods.org/pods/RxEventHub)
|
7 | 7 |
|
8 |
| -## Example |
| 8 | +## Overview |
9 | 9 |
|
10 |
| -To run the example project, clone the repo, and run `pod install` from the Example directory first. |
| 10 | +`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. |
| 11 | + |
| 12 | +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: |
| 13 | + |
| 14 | +```swift |
| 15 | +class ExampleIntEventProvider: RxEventProvider<Int>{} |
| 16 | +``` |
| 17 | + |
| 18 | +This class is used to provide type info and event name. You may override the `typeKey` method to provide custom event name. |
| 19 | + |
| 20 | +You can notify the hub when events occur by simply writing 1 line code like below: |
| 21 | + |
| 22 | +```swift |
| 23 | +RxEventHub.sharedHub.notify(ExampleIntEventProvider(), data: 2) |
| 24 | +``` |
| 25 | + |
| 26 | +You can get the `Observable` when events occur by simply writing 1 line code like below: |
| 27 | + |
| 28 | +```swift |
| 29 | +RxEventHub.sharedHub.eventObservable(ExampleIntEventProvider()) |
| 30 | +``` |
| 31 | + |
| 32 | +One more thing, you can either use the default hub `RxEventHub.sharedHub`, or create different hubs for different modules as you want. |
11 | 33 |
|
12 | 34 | ## Requirements
|
13 | 35 |
|
| 36 | +* Swift 2.x (use another branch for Swift 3, work in progress) |
| 37 | + |
14 | 38 | ## Installation
|
15 | 39 |
|
| 40 | +### CocoaPods |
| 41 | + |
16 | 42 | RxEventHub is available through [CocoaPods](http://cocoapods.org). To install
|
17 | 43 | it, simply add the following line to your Podfile:
|
18 | 44 |
|
19 | 45 | ```ruby
|
20 | 46 | pod "RxEventHub"
|
21 | 47 | ```
|
22 | 48 |
|
| 49 | +### Manual |
| 50 | + |
| 51 | +Just copy `RxEventHub.swift` into your project, and you're ready to go. |
| 52 | + |
23 | 53 | ## Author
|
24 | 54 |
|
25 | 55 |
|
|
0 commit comments