Skip to content

feat: Add Flow Signal documentation #4353

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

Merged
merged 5 commits into from
Jun 19, 2025
Merged

feat: Add Flow Signal documentation #4353

merged 5 commits into from
Jun 19, 2025

Conversation

mshabarov
Copy link
Contributor

@mshabarov mshabarov commented May 30, 2025

No description provided.

Copy link

github-actions bot commented May 30, 2025

AI Language Review

The provided documentation appears to be comprehensive and well-structured. It effectively explains the concepts of signals, their types, and usage within a Vaadin application. The examples are clear and the code snippets seem to accurately demonstrate the described features. The tone and style align well with technical documentation standards. Thus, there are no significant issues needing correction.

However, there is a minor typographical error noted: "soltuion" should be corrected to "solution". Other than this, the document is well-crafted.

@mshabarov mshabarov requested review from Legioth and taefi June 2, 2025 11:46
@mshabarov mshabarov marked this pull request as ready for review June 18, 2025 17:24
@@ -0,0 +1,393 @@
---
title: Reactive UI with Signals
page-title: How to create reactive UIs with the Flow Signals library
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume most readers don't know what a "reactive UI" is. The page title could instead be about "How to manage UI state".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

---
title: Reactive UI with Signals
page-title: How to create reactive UIs with the Flow Signals library
description: Using the Flow Signals library to manage UI state reactively in Vaadin applications.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an inconsistency between "the Flow Signals library" and "the Flow Signal library".

At the same time, I don't think it's relevant to give the name or emphasize that it's a library. From the user's point of view, it's just part of Flow just like the view router or the form binder (which are capitalized mainly when referring to the specific class but not when referring to the concept as a whole). I would thus prefer to use "signals in Flow" or just "signal".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Always be conservative when thinking about introducing new named concepts to the products. First try to describe/document them with common language, and if that becomes unwieldy or hard to comprehend, then you can try introducing a new named concept, that you very clearly define somewhere in the documentation.

== Introduction

The Flow Signal library provides a reactive state management solution for Vaadin Flow applications.
Its ultimate goal is to enable sharing state between multiple clients and the server in a thread-safe manner.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ultimate goal in the context of Flow is to make it easier to handle UI state regardless of whether it's shared. Thread-safe sharing and collaboration are just cherries on the top.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Vaadin Flow Signals library is a preview feature in Vaadin 24.8 and may change in future releases.
Signals integration into components API is planned in future releases but not yet included, thus you need to add listeners to components and effect functions manually.

=== Key Features
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in some comments above, I think the emphasis here could be shifted more towards "regular" state management.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


=== Effects

Effects are callbacks that automatically re-run when any signal value they depend on changes. They are used to update the UI in response to signal changes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could emphasize that dependency tracking is automatic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

[source,java]
----
Runnable cleanup = Signal.effect(() -> {
// Update UI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about avoiding examples that "use" effect together with anything related to the UI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


== Advanced Topics

=== Computed Signals
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like this belongs in the "advanced" section since it shows exactly the same thing that was already shown in the very beginning of the page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


=== Signal Mapping

You can transform a signal's value using the map() method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could mention that this is just a shorthand for creating a computed signal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

----
ValueSignal<String> name = SignalFactory.IN_MEMORY_SHARED.value("name", String.class);
ValueSignal<String> readOnlyName = name.asReadonly();
----
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could clarify that changes can still be made through name and that such changes will also be visible through readOnlyName

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


[source,java]
----
String name = nameSignal.peek(); // Won't trigger Signal.effect()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be easier to understand how this works if the code would be inside an actual effect callback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

@mshabarov mshabarov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These additions look good to me. Eager to merge 👍

Comment on lines 212 to 227
private final ValueSignal<String> value =
SignalFactory.IN_MEMORY_SHARED.value("value", "");

public UserForm() {
TextField nameField = new TextField("Name");
NumberField ageField = new NumberField("Age");

Signal.effect(() -> {
User currentUser = user.value();
nameField.setValue(currentUser.getName());
ageField.setValue(currentUser.getAge());
});
public SharedText() {
TextField field = new TextField("Value");

nameField.addValueChangeListener(event ->
user.update(u -> new User(event.getValue(), u.getAge())));
ComponentEffect.bind(field, value, TextField::setValue);

ageField.addValueChangeListener(event ->
user.update(u -> new User(u.getName(), event.getValue())));
field.addValueChangeListener(event -> {
// Only update signal if value has changed to avoid triggering infinite loop detection
if (!event.getValue().equals(value.peek())) {
value.value(event.getValue());
}
});

add(nameField, ageField);
add(field);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now looking at this (and older) example I'm thinking about adding one more component which value depends on the text input. Otherwise the code looks very synthetic: you input a value, it updates the signal and then it updates the value back to the same value, so visually Ui looks like as you just type a text. But from the other side, the example is anyway extremely simple, and rather should show the principle.

@mshabarov mshabarov merged commit 33095d0 into latest Jun 19, 2025
3 of 5 checks passed
@mshabarov mshabarov deleted the flow-signals branch June 19, 2025 10:02
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.

3 participants