Skip to content

Commit

Permalink
docs(framework): Fix for loop docs (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStegii authored Jun 5, 2024
1 parent 18354d8 commit 4d3c268
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions docs/features/2-for.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) -> {
Expand All @@ -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)
[⬅ Subscriber](1-subscriber.md) | [Overview](README.md) | [History ➡](3-history.md)

0 comments on commit 4d3c268

Please sign in to comment.