summaryrefslogtreecommitdiffstats
path: root/shared/src
diff options
context:
space:
mode:
authorAhmed Ashour <asashour@yahoo.com>2017-10-04 09:35:19 +0200
committerHenri Sara <henri.sara@gmail.com>2017-10-04 10:35:19 +0300
commitf265739578783ca08b7829ba030a38574b3ed4a7 (patch)
tree285b38dcb395e6a692d7a0ef61cb948fbc0cee97 /shared/src
parent80336d30ed12d53f24c01de5c4b6274ccc094b3b (diff)
downloadvaadin-framework-f265739578783ca08b7829ba030a38574b3ed4a7.tar.gz
vaadin-framework-f265739578783ca08b7829ba030a38574b3ed4a7.zip
Registration to remove state.registeredEventListeners (fixes #9634) (#10130)
This changes SharedState.registeredEventListeners to be a Map that keeps track of how many listeners of each type have been added, and handles unregistering of such listeners correctly.
Diffstat (limited to 'shared/src')
-rw-r--r--shared/src/main/java/com/vaadin/shared/communication/SharedState.java9
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/ComponentStateUtil.java29
2 files changed, 26 insertions, 12 deletions
diff --git a/shared/src/main/java/com/vaadin/shared/communication/SharedState.java b/shared/src/main/java/com/vaadin/shared/communication/SharedState.java
index 6b9c1045c5..57ad67a0d7 100644
--- a/shared/src/main/java/com/vaadin/shared/communication/SharedState.java
+++ b/shared/src/main/java/com/vaadin/shared/communication/SharedState.java
@@ -19,7 +19,6 @@ package com.vaadin.shared.communication;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import com.vaadin.shared.Connector;
import com.vaadin.shared.annotations.NoLayout;
@@ -62,10 +61,14 @@ public class SharedState implements Serializable {
public Map<String, URLReference> resources = new HashMap<>();
public boolean enabled = true;
+
/**
- * A set of event identifiers with registered listeners.
+ * A Map of event identifiers with registered listeners, {@code key} is
+ * event identifier, {@code value} is the listeners count.
+ *
+ * @since
*/
@NoLayout
- public Set<String> registeredEventListeners = null;
+ public Map<String, Integer> registeredEventListeners;
}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/ComponentStateUtil.java b/shared/src/main/java/com/vaadin/shared/ui/ComponentStateUtil.java
index 0ef247353b..a2f6618b9e 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/ComponentStateUtil.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/ComponentStateUtil.java
@@ -16,7 +16,7 @@
package com.vaadin.shared.ui;
import java.io.Serializable;
-import java.util.HashSet;
+import java.util.HashMap;
import com.vaadin.shared.AbstractComponentState;
import com.vaadin.shared.Registration;
@@ -67,12 +67,19 @@ public final class ComponentStateUtil implements Serializable {
@Deprecated
public static final void removeRegisteredEventListener(SharedState state,
String eventIdentifier) {
- if (state.registeredEventListeners == null) {
- return;
- }
- state.registeredEventListeners.remove(eventIdentifier);
- if (state.registeredEventListeners.size() == 0) {
- state.registeredEventListeners = null;
+ if (state.registeredEventListeners != null) {
+ Integer count = state.registeredEventListeners.get(eventIdentifier);
+ if (count != null) {
+ if (count > 1) {
+ state.registeredEventListeners.put(eventIdentifier,
+ count - 1);
+ } else {
+ state.registeredEventListeners.remove(eventIdentifier);
+ if (state.registeredEventListeners.isEmpty()) {
+ state.registeredEventListeners = null;
+ }
+ }
+ }
}
}
@@ -87,9 +94,13 @@ public final class ComponentStateUtil implements Serializable {
public static final Registration addRegisteredEventListener(
SharedState state, String eventListenerId) {
if (state.registeredEventListeners == null) {
- state.registeredEventListeners = new HashSet<>();
+ state.registeredEventListeners = new HashMap<>();
+ }
+ Integer count = state.registeredEventListeners.get(eventListenerId);
+ if (count == null) {
+ count = 0;
}
- state.registeredEventListeners.add(eventListenerId);
+ state.registeredEventListeners.put(eventListenerId, count + 1);
return () -> removeRegisteredEventListener(state, eventListenerId);
}
}