Skip to content

Allow subscriptions to be removed#455

Merged
route merged 1 commit intorubycdp:mainfrom
rzane:unsubscribe
Jan 8, 2025
Merged

Allow subscriptions to be removed#455
route merged 1 commit intorubycdp:mainfrom
rzane:unsubscribe

Conversation

@rzane
Copy link
Contributor

@rzane rzane commented Mar 23, 2024

This is admittedly not the most elegant API, but my goal is to start a discussion about how this should look.

Here's how you'd subscribe and unsubscribe:

subscription = page.on("Some.event") do |params, _index, _total|
  # etc
end

page.off("Some.event", subscription)

Here are some important considerations:

  • The #on method previously returned true. Now, it returns the index of the block within @on[event]. This could be considered a breaking change. Rather than using #on and #off, we could introduce a new method called #subscribe.
  • Rather than returning a value that identifies the specific event handler, we could return an object that has an #unsubscribe method.

@route route merged commit a49a934 into rubycdp:main Jan 8, 2025
@route
Copy link
Member

route commented Jan 8, 2025

Thank you! Looking solid now!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants