فهرست منبع

Fix handling of empty observation list.

Sam Jaffe 5 سال پیش
والد
کامیت
e45655031a

+ 4 - 2
src/main/lombok/org/leumasjaffe/observer/IndirectObservableListener.java

@@ -33,15 +33,17 @@ public class IndirectObservableListener<C, T> {
 	 */
 	public void setObserved( T obs, Observable... extra ) {
 		Objects.requireNonNull( obs );
-		if ( obs == model && (extra.length == 0 || extra[0] == obs) ) return;
 		// Make sure that we aren't listening to any of the previous things.
 		// This means that we can re-use objects instead of destroying and re-making a
 		// bunch of high-level GUI objects any time the model changes.
 		ObserverDispatch.unsubscribeAll( this );
+		final boolean hasChanged = (obs != model);
 		model = obs;
 		// Invoke the update callback - our parent does not need to update the
 		// {@see component} manually.
-		updateComponent( );
+		if (hasChanged) {
+			updateComponent( );
+		}
 		for ( int i = 0, n = extra.length; i < n; ++i ) {
 			ObserverDispatch.subscribe( extra[i], this, this::updateComponent );
 		}

+ 1 - 0
src/main/lombok/org/leumasjaffe/observer/ObservableListener.java

@@ -26,6 +26,7 @@ public class ObservableListener<C, T extends Observable> {
 	 * {@see IndirectObservableListener#setObserved}
 	 */
 	public void setObserved( T obs ) {
+		if (impl.getModel() == obs) { return; }
 		impl.setObserved(obs, obs);
 	}