Latest 0.2.0
Homepage https://github.com/LeoMobileDeveloper/SugarBus
License MIT
Platforms ios 8.0
Authors

SugarBus

Version Platform
Language
License

中文文档

  • [x] Fast
  • [x] Async
  • [x] Thread Safe
  • [x] 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.

Latest podspec

{
    "name": "SugarBus",
    "version": "0.2.0",
    "summary": "Fast and type safe event bus for swift.",
    "description": "SugarBus is an event bus for Swift.It helps you to  write elegant code about Events in swift, bye bye `NSNotification`u3002",
    "homepage": "https://github.com/LeoMobileDeveloper/SugarBus",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Leo": "[email protected]"
    },
    "source": {
        "git": "https://github.com/LeoMobileDeveloper/SugarBus.git",
        "tag": "0.2.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Sources/**/*"
}

Pin It on Pinterest

Share This