-
Notifications
You must be signed in to change notification settings - Fork 210
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
Conversation
AI Language ReviewThe 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. |
articles/flow/advanced/signals.adoc
Outdated
@@ -0,0 +1,393 @@ | |||
--- | |||
title: Reactive UI with Signals | |||
page-title: How to create reactive UIs with the Flow Signals library |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
articles/flow/advanced/signals.adoc
Outdated
--- | ||
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. |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
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.
articles/flow/advanced/signals.adoc
Outdated
== 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
articles/flow/advanced/signals.adoc
Outdated
|
||
=== 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
articles/flow/advanced/signals.adoc
Outdated
[source,java] | ||
---- | ||
Runnable cleanup = Signal.effect(() -> { | ||
// Update UI |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
articles/flow/advanced/signals.adoc
Outdated
|
||
== Advanced Topics | ||
|
||
=== Computed Signals |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
articles/flow/advanced/signals.adoc
Outdated
|
||
=== Signal Mapping | ||
|
||
You can transform a signal's value using the map() method. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); | ||
---- |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
articles/flow/advanced/signals.adoc
Outdated
|
||
[source,java] | ||
---- | ||
String name = nameSignal.peek(); // Won't trigger Signal.effect() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Make the bot happier
There was a problem hiding this 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 👍
articles/flow/advanced/signals.adoc
Outdated
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); |
There was a problem hiding this comment.
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.
No description provided.