Skip to content

mikhailvs/simple-event-bus

Repository files navigation

SimpleEventBus

Gem Version

Install

Gemfile:

gem 'simple-event-bus'

Shell:

gem install simple-event-bus

Usage

Use the SimpleEventBus class as a singleton, or instantiate new instances of it.

require 'event-bus'

SimpleEventBus.subscribe(:event_happened) do |params|
  puts "Event handled with block: #{params.inspect}"
end

class EventHandler
  def event_happened(params)
    puts "Event handled with method: #{params.inspect}"
  end
end

SimpleEventBus.emit(:event_happened, param1: 'hello', param2: 'world')

bus = SimpleEventBus.new

bus.subscribe(:event_happened, EventHandler.new, once: true)

bus.emit(:event_happened, request: 'handle THIS')

Releases

No releases published

Packages

No packages published

Languages