com

CommandBus

A light weight Command Bus implementation written in Swift

Showing:

Popularity

Downloads/wk

0

GitHub Stars

39

Maintenance

Last Commit

6yrs ago

Contributors

1

Package

Dependencies

1

License

MIT

Categories

Readme

CommandBus

Version License Platform ![](https://img.shields.io/badge/Swift 2-compatible-4BC51D.svg?style=flat-square)

A light weight Command Bus implementation written in Swift

CommandBus?

The idea of a command bus is that you create command objects that represent what you want your application to do. Then, you toss it into the bus and the bus makes sure that the command object gets to where it needs to go.

So, the command goes in -> the bus hands it off to a handler -> and then the handler actually does the job. The command essentially represents a method call to your application layer.

You can have more informations here.

Installation

CocoaPods

CommandBus is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "CommandBus", '~> 0.0.7'

Usage

  • First, you have to create a json mapping file in order to associate yours Commands with their handler:
{
    "{CommandNameA}": "{CommandHandlerNameA}",
    "{CommandNameB}": "{CommandHandlerNameB}",
    "{CommandNameC}": "{CommandHandlerNameC}"
}
  • Then you can create your Command and inject it to the bus:
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        /*** Register to the Command event ***/
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "onCommandHandled:", name:"COMMAND_DONE", object: nil)
        
        /*** Create the CommandBus ***/
        let commandBus: CommandBus = CommandBus(configurationFileName: "configuration")!
        
        /*** Create your own Command ***/
        let customCommand: CustomCommand = CustomCommand()
        
        /*** Send your command to the CommandBus with your event name ***/
        commandBus.handle(command: customCommand, commandHandledEvent: "COMMAND_DONE")
    }

    func onCommandHandled(notification: NSNotification) {
        /*** This method is called when the CommandHandler have done ***/
        print("Command Handled: \(notification.object!)")
    }
}

You can also see the Example project.

Author

Ekhoo:

License

CommandBus is available under the MIT license. See the LICENSE file for more info.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100