Skip to content

Commit 119f9f4

Browse files
authored
chore!: Remove ComponentEffect.format (#22230)
Fixes #22167
1 parent cc5d030 commit 119f9f4

File tree

2 files changed

+1
-159
lines changed

2 files changed

+1
-159
lines changed

flow-server/src/main/java/com/vaadin/flow/component/ComponentEffect.java

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515
*/
1616
package com.vaadin.flow.component;
1717

18-
import java.util.Locale;
1918
import java.util.Objects;
20-
import java.util.stream.Stream;
2119

2220
import com.vaadin.flow.function.SerializableBiConsumer;
23-
import com.vaadin.flow.internal.LocaleUtil;
2421
import com.vaadin.flow.server.ErrorEvent;
2522
import com.vaadin.flow.shared.Registration;
2623
import com.vaadin.signals.Signal;
@@ -35,7 +32,7 @@
3532
* {@link Signal#effect(Runnable)}, that is automatically enabled when a
3633
* component is attached and disabled when the component is detached.
3734
* Additionally it provides methods to bind signals to component according to a
38-
* given value setting function and format strings based on signal values.
35+
* given value setting function.
3936
*
4037
* @since 24.8
4138
*/
@@ -137,97 +134,6 @@ public static <C extends Component, T> Registration bind(C owner,
137134
});
138135
}
139136

140-
/**
141-
* Formats a string using the values of the provided signals and the given
142-
* locale, sets the formatted string on the owner component using the
143-
* provided setter function.
144-
* <p>
145-
* Binds a formatted string using the values of the provided signals to a
146-
* given owner component in a way defined in <code>setter</code> function
147-
* and creates a Signal effect function executing the setter whenever the
148-
* signal value changes.
149-
* <p>
150-
* Example of usage:
151-
*
152-
* <pre>
153-
* ComponentEffect.format(mySpan, Span::setText, Locale.US,
154-
* "The price of %s is %.2f", nameSignal, priceSignal);
155-
* </pre>
156-
*
157-
* @see Signal#effect(Runnable)
158-
* @param owner
159-
* the owner component for which the effect is applied, must not
160-
* be <code>null</code>
161-
* @param setter
162-
* the setter function that defines how the formatted string is
163-
* applied to the component, must not be <code>null</code>
164-
* @param locale
165-
* the locale to be used for formatting the string, if
166-
* <code>null</code>, then no localization is applied
167-
* @param format
168-
* the format string to be used for formatting the signal values,
169-
* must not be <code>null</code>
170-
* @param signals
171-
* the signals whose values are to be used for formatting the
172-
* string, must not be <code>null</code>
173-
* @return a {@link Registration} that can be used to remove the effect
174-
* function
175-
* @param <C>
176-
* the type of the component
177-
*/
178-
public static <C extends Component> Registration format(C owner,
179-
SerializableBiConsumer<C, String> setter, Locale locale,
180-
String format, Signal<?>... signals) {
181-
return effect(owner, () -> {
182-
Object[] values = Stream.of(signals).map(Signal::value).toArray();
183-
setter.accept(owner, String.format(locale, format, values));
184-
});
185-
}
186-
187-
/**
188-
* Formats a string using the values of the provided signals and sets it on
189-
* the owner component using the provided setter function.
190-
* <p>
191-
* Binds a formatted string using the values of the provided signals to a
192-
* given owner component in a way defined in <code>setter</code> function
193-
* and creates a Signal effect function executing the setter whenever the
194-
* signal value changes.
195-
* <p>
196-
* Formats using locale from the current UI, I18NProvider or default locale
197-
* depending on what is available.
198-
* <p>
199-
* Example of usage:
200-
*
201-
* <pre>
202-
* ComponentEffect.format(mySpan, Span::setText, "The price of %s is %.2f",
203-
* nameSignal, priceSignal);
204-
* </pre>
205-
*
206-
* @see Signal#effect(Runnable)
207-
* @param owner
208-
* the owner component for which the effect is applied, must not
209-
* be <code>null</code>
210-
* @param setter
211-
* the setter function that defines how the formatted string is
212-
* applied to the component, must not be <code>null</code>
213-
* @param format
214-
* the format string to be used for formatting the signal values,
215-
* must not be <code>null</code>
216-
* @param signals
217-
* the signals whose values are to be used for formatting the
218-
* string, must not be <code>null</code>
219-
* @return a {@link Registration} that can be used to remove the effect
220-
* function
221-
* @param <C>
222-
* the type of the component
223-
*/
224-
public static <C extends Component> Registration format(C owner,
225-
SerializableBiConsumer<C, String> setter, String format,
226-
Signal<?>... signals) {
227-
Locale locale = LocaleUtil.getLocale();
228-
return format(owner, setter, locale, format, signals);
229-
}
230-
231137
private void enableEffect(Component owner) {
232138
if (closed) {
233139
return;

flow-server/src/test/java/com/vaadin/flow/component/ComponentEffectTest.java

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import static org.mockito.Mockito.when;
2626

2727
import java.util.ArrayList;
28-
import java.util.Locale;
2928
import java.util.concurrent.CountDownLatch;
3029
import java.util.concurrent.LinkedBlockingQueue;
3130
import java.util.concurrent.TimeUnit;
@@ -44,7 +43,6 @@
4443
import com.vaadin.flow.server.VaadinService;
4544
import com.vaadin.flow.server.VaadinSession;
4645
import com.vaadin.flow.shared.Registration;
47-
import com.vaadin.signals.NumberSignal;
4846
import com.vaadin.signals.ValueSignal;
4947
import com.vaadin.tests.util.MockUI;
5048

@@ -277,68 +275,6 @@ public void bind_signalValueChanges_componentUpdated() {
277275
});
278276
}
279277

280-
@Test
281-
public void format_customLocale_signalValuesChange_formattedStringUpdated() {
282-
runWithFeatureFlagEnabled(() -> {
283-
TestComponent component = new TestComponent();
284-
285-
MockUI ui = new MockUI();
286-
ui.add(component);
287-
288-
ValueSignal<String> stringSignal = new ValueSignal<>("test");
289-
NumberSignal numberSignal = new NumberSignal(42.23456);
290-
291-
Registration registration = ComponentEffect.format(component,
292-
TestComponent::setValue, Locale.ENGLISH,
293-
"The price of %s is %.2f", stringSignal, numberSignal);
294-
295-
assertEquals("Initial formatted value should be set",
296-
"The price of test is 42.23", component.getValue());
297-
298-
// Change int signal value
299-
numberSignal.value(20.12345);
300-
301-
assertEquals(
302-
"Formatted value should be updated with new numeric value",
303-
"The price of test is 20.12", component.getValue());
304-
305-
// Change string signal value
306-
stringSignal.value("updated");
307-
308-
assertEquals(
309-
"Formatted value should be updated with new string value",
310-
"The price of updated is 20.12", component.getValue());
311-
312-
registration.remove();
313-
314-
numberSignal.value(30.3456);
315-
stringSignal.value("final");
316-
317-
assertEquals(
318-
"Formatted value should not be updated after registration is removed",
319-
"The price of updated is 20.12", component.getValue());
320-
});
321-
}
322-
323-
@Test
324-
public void format_defaultLocale_signalValuesChange_formattedStringUpdated() {
325-
runWithFeatureFlagEnabled(() -> {
326-
TestComponent component = new TestComponent();
327-
328-
MockUI ui = new MockUI();
329-
ui.add(component);
330-
331-
ValueSignal<String> stringSignal = new ValueSignal<>("test");
332-
ValueSignal<Integer> numberSignal = new ValueSignal<>(42);
333-
334-
ComponentEffect.format(component, TestComponent::setValue,
335-
"The price of %s is %d", stringSignal, numberSignal);
336-
337-
assertEquals("Initial formatted value should be set",
338-
"The price of test is 42", component.getValue());
339-
});
340-
}
341-
342278
@FunctionalInterface
343279
private interface InterruptableRunnable {
344280
void run() throws InterruptedException;

0 commit comments

Comments
 (0)