From 4d3c26850ea1757966593e37d8c29b03457e2098 Mon Sep 17 00:00:00 2001 From: Paul Mertens <50475262+LeStegii@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:08:47 +0200 Subject: [PATCH] docs(framework): Fix for loop docs (#107) --- docs/features/2-for.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/features/2-for.md b/docs/features/2-for.md index 40bb97c7..07c22038 100644 --- a/docs/features/2-for.md +++ b/docs/features/2-for.md @@ -12,7 +12,7 @@ fxFor.of(container, items, myComponentProvider); This will create a component for each item in the list `items` and add it to the children of the `container` (e.g. a VBox). -Currently, no information is passed to the created label. In order to pass static information you can add +Currently, no information is passed to the created component. In order to pass static information you can add parameters like you would when using the `show`-method using a map. When a new component is created, the parameters `item` and `list` are automatically added to the map. The `item` parameter contains the current item of the component and the `list` parameter contains the list of all items. @@ -23,30 +23,30 @@ fxFor.of(container, items, myComponentProvider, Map.of("key", value)); fxFor.of(container, items, myComponentProvider, params); // Parameters can be taken from the @Params annotation for example ``` -If you want to pass dynamic information like binding the item to its controller, you can use an `BiConsumer`. -The `BiConsumer` allows to define actions for initializing each controller based on its item. +If you want to pass dynamic information like binding the item to its component, you can use an `BiConsumer`. +The `BiConsumer` allows to define actions for initializing each component based on its item. ```java -fxFor.of(container, items, myComponentProvider, (controller, item) -> { - controller.setItem(item); - controller.foo(); - controller.bar(); +fxFor.of(container, items, myComponentProvider, (component, item) -> { + component.setItem(item); + component.foo(); + component.bar(); }); fxFor.of(container, items, myComponentProvider, ExampleComponent::setItem); // Short form using method references fxFor.of(container, items, myComponentProvider, Map.of("key", value), ExampleComponent::setItem); // Static and dynamic information can be passed together ``` -Instead of a controller you can also define a basic JavaFX node to display for every item. +Instead of a component you can also define a basic JavaFX node to display for every item. ```java fxFor.of(container, items, () -> new Button("This is a button!")); fxFor.of(container, items, () -> new VBox(new Button("This is a button!"))); // Nodes can have children ``` -Unlike with controllers, it is not possible to pass static information in the form of parameters to nodes, as there is no +Unlike with components, it is not possible to pass static information in the form of parameters to nodes, as there is no way of accessing them in the code. However, dynamic information in the form of an `BiConsumer` can be used just like with -controllers. +components. ```java fxFor.of(container, items, () -> new Button(), (button, item) -> { @@ -55,9 +55,9 @@ fxFor.of(container, items, () -> new Button(), (button, item) -> { }); ``` -In order to destroy controllers generated by the For-loops, you can use the `dispose()` method of the `For` class or add +In order to destroy components generated by the For-loops, you can use the `dispose()` method of the `For` class or add the return value of the `disposable()` method to your list of disposables. --- -[⬅ Subscriber](1-subscriber.md) | [Overview](README.md) | [History ➡](3-history.md) \ No newline at end of file +[⬅ Subscriber](1-subscriber.md) | [Overview](README.md) | [History ➡](3-history.md)