Skip to content

stanfeldman/Eventer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Publish/subscribe to enum events in Swift

This is type-safe publish/subscribe implementation, where you use custom enums as events.

Events

Inherit Event protocol in your events enum.

enum User: Event {
    case Followed
    case Unfollowed
}

Subscription

You can subscribe to closure.

Eventer.subscribe(Events.User.Followed) {
  
}

And you can subscribe to function or method.

Eventer.subscribe(Events.User.Unfollowed, action: self.onNeedToReload)

Closure or function can be with or without info argument.

Eventer.subscribe(Events.User.Followed) { (info) in
  
}

You can use subscribe to several events.

Eventer.subscribe([Events.User.Followed, Events.User.Unfollowed], action: self.onNeedToReload)

Publishing

You can publish events defined in custom enums.

Eventer.publish(Events.User.Followed)

And you can publish events with additional info.

Eventer.publish(Events.Route.Added, info: "Super user")

You can asynchronously publish events in background or main thread.

Eventer.publish(Events.User.Followed, to: .Background)
Eventer.publish(Events.User.Followed, to: .Main)

About

Publish/subscribe to enum events in Swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages