Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Be able to configure default callbacks #367

Closed
frostmark opened this issue Dec 27, 2021 · 0 comments
Closed

Be able to configure default callbacks #367

frostmark opened this issue Dec 27, 2021 · 0 comments

Comments

@frostmark
Copy link
Contributor

frostmark commented Dec 27, 2021

Hi there!

I would like to suggest adding the ability for configuring default callbacks (for example, on_assignment)

I see an interface something like this:

Vanity.configure do |config|
  config.on_assignment = proc do |...params|
    # does something useful 
  end
  
  config.after_assignment = proc do |...params|
    # does something useful 
  end
end

Also, we can redefine the default callback if we define that inside some test

# on_assignment do |controller, identity, assignment|

That will help define some logic once. In my case: I want to make pub/sub logic and broadcast events from after_assignment callback:

class VanityEventPublisher
  include Wisper::Publisher

  def after_assignment(assignment)
    broadcast(:after_assignment, assignment)
  end
end

class AbTestEventListener
  def after_assignment(assignment)
    Analytics::Tracker.track!(:some_event)
  end
end

Vanity.configure do |config|
  config.after_assignment = proc do |assignment|
    VanityEventPublisher.new.after_assignment(assignment)
  end
end

Also, I think this would be helpful for some loggers and so on

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant