emittr
                                
                                
                                
                                    emittr copied to clipboard
                            
                            
                            
                        Implement namespaces
It would be cool to support namespaces. Something like:
class User
  attr_reader :name
  def initialize(name:, emitter:)
    @name = name
    @emitter = emitter
  end
  def sign_in!
    # do something
    @emitter.emit('user::sign_in', self)
  end
end
emitter = Emittr::Emitter.new
user = User.new(name: 'Name for a bad example', emitter: emitter)
emitter.on 'user::*', do |event_name, u|
  puts "#{event_name} emitted for user #{u.name}"
end
                                    
                                    
                                    
                                
@rscardinho what do you think about it?
It could also be implemented using a regex for the first parameter  of on/once methods instead of a string. Maybe that would be even more flexible:
emitter = Emittr::Emitter.new
emitter.on /^user::\w+/ do |event_name|
   puts event_name
end
emitter.emit 'user::create'
#=> user::create
I would make it a little more verbose, perhaps.
yeah, good idea. I've thought on something similar, but I forgot to write down anywhere. HEHE
For me, the regex example is way more flexible than the string implementation, but what about both implementations? 🚀