SugarBus
- Fast
- Async
- Thread Safe
- Type Safe
SugarBus in 3 steps
Define events with any type you want
struct DemoEvent: Event{
//Any property you want
}
Subscribe event
DemoEvent.addSubscriber().next { (event) in }
Publish Event
DemoEvent().publish()
Require
- iOS 8
- Swift 4
Install
pod SugarBus
Features
Thread
By deault, all callback hander is invoked on main thread, if you want to receive it on another thread:
Event.addSubscriber().at(queue:yourqueue).next { (event) in }
Life Circle Tracker
Most times, you want to unsubscribe an event when a object is dealloced. You can using attach(to:)
to achive this.
//When self is dealloced, disposed() is called
Event.addSubscriber().attach(to:self).next { (event) in }
If you want to manual handle dispose
let token = Event.addSubscriber().next { (event) in }
token.dispose()
Event Id
Sometimes, you only interested in a special id of event.
1.Provide eventId
struct DownloadEvent: Event{
var eventId: String{
return itemId
}
let itemId: String
}
2.Use only
to subscribe
DownloadEvent.addSubscriber()
.attach(to:self)
.only(id:"12345")
.next{ (event) in
}
3.Publish
DownloadEvent(itemId:"12345").publish()
Author
Leo, [email protected]
License
SugarBus is available under the MIT license. See the LICENSE file for more info.