palkan / active_event_store

Rails Event Store in a more Rails way
MIT License
181 stars 13 forks source link

RailsEventStore::Browser doesn't work out of the box #17

Closed Samsinite closed 4 months ago

Samsinite commented 5 months ago

What did you do?

Tried to mount RailsEventStore::Browser engine and load the page (followed these instructions).

What did you expect to happen?

The page would load and I would be able to browse through the various events and stream specific events.

What actually happened?

It errored when trying to look up the event store using Rails.configuration.event_store because it was undefined.

Additional context

Creating a custom engine that used:

endpoint RubyEventStore::Browser::App.for(event_store_locator: -> { ActiveEventStore.event_store })

worked instead.

Can you think of an ideal way that active event store could be setup so that using this engine just works? My initial thoughts are that this library can define its own engine to include instead, and add a section to the README about it:

# frozen_string_literal: true

require "ruby_event_store/browser/app"
require "rails/engine"

module ActiveEventStore
  class Browser < Rails::Engine
    endpoint RubyEventStore::Browser::App.for(event_store_locator: -> { ActiveEventStore.event_store })

    railtie_name "ruby_event_store_browser_app"
  end
end

But maybe a different approach would be better (such as calling RailsEventStore::Browser.endpoint RubyEventStore::Browser::App.for(event_store_locator: -> { ActiveEventStore.event_store }) after ActiveEventStore.event_store is set). Or if you aren't interested in supporting this engine out of the box, no worries, it is easy enough to define a custom one in-app. If you are interested in supporting this engine using active event store, let me know what apporach you'd like to take, I'd be happy to take a stab at it.

Edit:

Actually, I think just calling

RailsEventStore::Browser.endpoint RubyEventStore::Browser::App.for(event_store_locator: -> { ActiveEventStore.event_store })

In the config.to_prepare do block after ActiveEventStore.event_store is set would work best and "just work" as expected for developers.

palkan commented 5 months ago

I wonder if we'd better use Rails.configuration.event_store as an alias for ActiveEventStore.event_store as it's the "recommended location"?

That means, adding an initializers (in the Railtie) setting Rails.configuration.event_store = ActiveEventStore.event_store would make the browser work (and other tools relying on the default location).