-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Events] Add subscribers automatically #3571
[Events] Add subscribers automatically #3571
Conversation
59b2c11
to
60f7746
Compare
60f7746
to
60e4b0f
Compare
A couple of questions:
|
@kennyadsl here you are my answers to your questions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, loading core subscribers automatically works for me. I have some concerns just in case we may want to add extra logic in the future, for example, deprecating a subscriber and avoiding it to be always loaded, but we can face it when/if this will happen.
I'm not 100% sure about this to be honest, I think it adds a layer of magic that we may not need. It could be particularly confusing considering that core subscribers are loaded automatically, while extensions will have to register their subscribers manually. At the end of the day, is it really worth it? 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern here would be making sure this all works properly with code reloading.
@jarednorman I just checked, code reload still works fine in development (kudos go to @elia for the implementation). |
We discussed this during a core team meeting and, since the plan is to add the same capability to extensions, I'm happy to move forward with this! 🚀 Thanks @spaghetticode and @elia. |
Cool. I'll hold off giving this an approval since it's still listed as "Needs Work" but I'm favour of this change overall. |
de5ba6e
to
adcf05d
Compare
@spaghetticode looks like f8f392a somehow ended up in this branch 😄 Can you remove it? |
The preference `Spree::Config.event.autoload_subscribers` can be used for disabling the automatic loading of Solidus event subscribers. The preference is set to `true` by default, developers can opt out by creating an intializers that sets the preference to false: Spree::Config.event.autoload_subscribers = false
Until now, adding subscribers to Spree::Event.subscribers was developers' responsibility. This commit aims at automating the task by making Rails load subscriber files located in standard paths both in Solidus core and in the store app during the Rails initialization processs. When each file is required, it's now also added to the `Spree::Event.subscribers` list. Solidus core event subscribers are always loaded automatically, while the ones included in the store app can be loaded manually when the preference Spree::Config.events.autoload_subscribers is changed to a falsey value. A similar feature will be added to `solidus_support` in order to automatically subscribe subscribers from extensions.
Documenting automatic loading of files and subscription of subscribers when their files are placed under the directory `app/subscribers` and end with `_subscriber.rb`.
adcf05d
to
d617740
Compare
@spaghetticode GTM! |
Description
(This PR is based on some work done by @elia and @AlessioRocco for Meundies)
Until now, adding subscribers to
Spree::Event.subscribers
was developers' responsibility.This PR aims at automating the task by making Rails load subscriber files located in standard paths both in Solidus core and in the store app during the Rails initialization processs. When each file is required, it's now also added to the
Spree::Event.subscribers
list.Checklist: