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

scala.swing.Publisher.publish should take account of PartialFunctions #8020

Closed
scabug opened this issue Nov 29, 2013 · 1 comment
Closed

Comments

@scabug
Copy link

scabug commented Nov 29, 2013

Compare Publisher.publish

  def publish(e: Event) { for (l <- listeners) l(e) }

and Reactions.Impl.apply

  def apply(e: Event) {
    for (p <- parts) if (p isDefinedAt e) p(e)
  }

This means that if we have the following code

    val l: Reaction = {
      case ButtonClicked(b) => println("Button pushed")
    }
    // This should work, or not be available in the API ;)
    button.subscribe(l)
    // This works
    button.reactions += l

it will give lots of MatchErrors (e.g. when FocusGained/FocusLost events are fired) if we add the listener with the first construct, whereas it works fine in the second construct.

(Actually, why are there two different ways of adding listeners in the first place?)

@scabug
Copy link
Author

scabug commented Nov 29, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8020?orig=1
Reporter: Robert Gibson (rgibson)
Affected Versions: 2.10.3
Duplicates #8019

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

No branches or pull requests

1 participant