Skip to content
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

Fix subscriptions not being unsubscribed. #14642

Merged
merged 1 commit into from Apr 15, 2014

Conversation

tgxworld
Copy link
Contributor

@tgxworld tgxworld commented Apr 8, 2014

@tgxworld
Copy link
Contributor Author

tgxworld commented Apr 8, 2014

@senny Please review. Came across it while working on actionpack. Thanks :)

@tgxworld
Copy link
Contributor Author

tgxworld commented Apr 8, 2014

I just noticed the failing test, will fix soon

@tgxworld
Copy link
Contributor Author

@senny Fixed :)

@senny
Copy link
Member

senny commented Apr 14, 2014

@tgxworld the docs mention:

  # The +subscribe+ method returns a subscriber object:
  #
  #   subscriber = ActiveSupport::Notifications.subscribe("render") do |*args|
  #     ...
  #   end
  #
  # To prevent that block from being called anymore, just unsubscribe passing
  # that reference:
  #
  #   ActiveSupport::Notifications.unsubscribe(subscriber)

Can we rename the instance variables to _subscriber?

@tgxworld
Copy link
Contributor Author

@senny Thanks for the review :) I've made the changes.

Just to point out, I guess the changes here are fine since there was a conflicting use of @subscriber? :)

@senny
Copy link
Member

senny commented Apr 14, 2014

@tgxworld yea that's fine. Just went through the docs and saw that we usually call it subscriber. Good to keep that wording. Thanks for the update.

@@ -53,8 +53,9 @@ def setup_subscriptions
end

def teardown_subscriptions
ActiveSupport::Notifications.unsubscribe("render_template.action_view")
ActiveSupport::Notifications.unsubscribe("!render_template.action_view")
[@layouts_subscriber, @partials_subscriber, @files_subscriber].each do |subscriber|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact that one subscription was added but forgotten in the removal process is a smell. Let's go one step further and refactor this to:

@_subscribers = []
# ...
@_subscribers << ActiveSupport::Notifications.subscribe("A")
@_subscribers << ActiveSupport::Notifications.subscribe("B")
@_subscribers << ActiveSupport::Notifications.subscribe("C")

# loop over @_subscribers to remove them.

This should be easier to keep in sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tgxworld
Copy link
Contributor Author

@senny Updated per your comments :)

senny added a commit that referenced this pull request Apr 15, 2014
…ribing

Fix subscriptions not being unsubscribed.
@senny senny merged commit ab529c8 into rails:master Apr 15, 2014
@senny
Copy link
Member

senny commented Apr 15, 2014

@tgxworld looking good 💛

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

Successfully merging this pull request may close these issues.

None yet

3 participants