Skip to content

Commit 1b76129

Browse files
committed
Replaced createActionSubscriber() functionality with simple dispatch()-methods.
Removed SimpleReduxFXStore. Removed default drivers. Removed functionality to attach ReduxFXView to 3rd-party store.
1 parent 45b95a9 commit 1b76129

File tree

47 files changed

+347
-1219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+347
-1219
lines changed

examples/colorchooser/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<groupId>com.netopyr.reduxfx</groupId>
3333
<artifactId>reduxfx-view</artifactId>
3434
</dependency>
35+
<dependency>
36+
<groupId>org.slf4j</groupId>
37+
<artifactId>slf4j-simple</artifactId>
38+
</dependency>
3539
</dependencies>
3640

3741
</project>

examples/colorchooser/src/main/java/com/netopyr/reduxfx/examples/colorchooser/app/ColorChooserApp.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.netopyr.reduxfx.examples.colorchooser.app.updater.Updater;
55
import com.netopyr.reduxfx.examples.colorchooser.app.view.MainView;
66
import com.netopyr.reduxfx.middleware.LoggingMiddleware;
7-
import com.netopyr.reduxfx.store.SimpleReduxFXStore;
7+
import com.netopyr.reduxfx.store.ReduxFXStore;
88
import com.netopyr.reduxfx.vscenegraph.ReduxFXView;
99
import javafx.application.Application;
1010
import javafx.scene.paint.Color;
@@ -21,13 +21,10 @@ public void start(Stage primaryStage) throws Exception {
2121
final AppState initialState = AppState.create().withColor(Color.VIOLET);
2222

2323
// Setup the ReduxFX-store passing the initialState and the update-function
24-
final SimpleReduxFXStore<AppState> store = new SimpleReduxFXStore<>(initialState, Updater::update, new LoggingMiddleware<>());
24+
final ReduxFXStore<AppState> store = new ReduxFXStore<>(initialState, Updater::update, new LoggingMiddleware<>());
2525

26-
// Setup the ReduxFX-view passing the view-function and the primary stage that should hold the calculated view
27-
final ReduxFXView<AppState> view = ReduxFXView.createStage(MainView::view, primaryStage);
28-
29-
// Connect store and view
30-
view.connect(store.getStatePublisher(), store.createActionSubscriber());
26+
// Setup the ReduxFX-view passing the store, the view-function and the primary stage that should hold the calculated view
27+
ReduxFXView.createStage(store, MainView::view, primaryStage);
3128
}
3229

3330
public static void main(String[] args) {

examples/colorchooser/src/main/java/com/netopyr/reduxfx/examples/colorchooser/app/updater/Updater.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.netopyr.reduxfx.examples.colorchooser.app.actions.UpdateColorAction;
44
import com.netopyr.reduxfx.examples.colorchooser.app.state.AppState;
5+
import com.netopyr.reduxfx.updater.Update;
56

67
import java.util.Objects;
78

@@ -43,25 +44,28 @@ private Updater() {
4344
* @return the new {@code AppState}
4445
* @throws NullPointerException if state or action are {@code null}
4546
*/
46-
public static AppState update(AppState state, Object action) {
47+
public static Update<AppState> update(AppState state, Object action) {
4748
Objects.requireNonNull(state, "The parameter 'state' must not be null");
4849
Objects.requireNonNull(action, "The parameter 'action' must not be null");
4950

50-
// This is part of Vavr's pattern-matching API. It works similar to the regular switch-case
51-
// in Java, except that it is much more flexible and returns a value.
52-
// We check which of the cases is true and in that branch we specify the newState.
53-
return Match(action).of(
51+
return Update.of(
5452

55-
// If the action is a UpdateColorAction, we return a new AppState with the
56-
// property color set to the new value.
57-
Case($(instanceOf(UpdateColorAction.class)),
58-
updateColorAction -> state.withColor(updateColorAction.getValue())
59-
),
53+
// This is part of Vavr's pattern-matching API. It works similar to the regular switch-case
54+
// in Java, except that it is much more flexible and returns a value.
55+
// We check which of the cases is true and in that branch we specify the newState.
56+
Match(action).of(
6057

61-
// This is the default branch of this switch-case. If an unknown action was passed to the
62-
// updater, we simply return the old state. This is a convention, that is not needed right
63-
// now, but will help once you start to decompose your updater.
64-
Case($(), state)
58+
// If the action is a UpdateColorAction, we return a new AppState with the
59+
// property color set to the new value.
60+
Case($(instanceOf(UpdateColorAction.class)),
61+
updateColorAction -> state.withColor(updateColorAction.getValue())
62+
),
63+
64+
// This is the default branch of this switch-case. If an unknown action was passed to the
65+
// updater, we simply return the old state. This is a convention, that is not needed right
66+
// now, but will help once you start to decompose your updater.
67+
Case($(), state)
68+
)
6569
);
6670
}
6771
}

examples/colorchooser/src/main/java/com/netopyr/reduxfx/examples/colorchooser/component/ColorChooserComponent.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.netopyr.reduxfx.component.ComponentBase;
99
import com.netopyr.reduxfx.examples.colorchooser.app.view.MainView;
1010
import com.netopyr.reduxfx.middleware.LoggingMiddleware;
11+
import com.netopyr.reduxfx.store.Driver;
1112
import com.netopyr.reduxfx.vscenegraph.ReduxFXView;
1213
import com.netopyr.reduxfx.vscenegraph.builders.Factory;
1314
import javafx.beans.property.ObjectProperty;
@@ -20,7 +21,7 @@
2021
*
2122
* It extends {@code VBox} and adds one additional JavaFX property {@link #colorProperty()}. As usual in ReduxFX,
2223
* we do not want to modify state directly and this also applies to JavaFX properties of the public interface.
23-
* Instead we use a {@link com.netopyr.reduxfx.driver.Driver} for that. We can send commands to the driver to update
24+
* Instead we use a {@link Driver} for that. We can send commands to the driver to update
2425
* the value of the JavaFX property. Commands are created in the {@link ColorChooserUpdater} together with the state
2526
* changes. If the value of a JavaFX property changes, our updater receives an action, which can be specified here.
2627
*/
@@ -47,15 +48,12 @@ public ColorChooserComponent() {
4748
// Setup the initial state
4849
final ColorChooserState initialData = new ColorChooserState();
4950

50-
// A ComponentBase is the central piece of every component implemented with ReduxFX. It creates a separate
51+
// A component-base is the central piece of every component implemented with ReduxFX. It creates a separate
5152
// ReduxFX-store for the component and acts as the factory for all JavaFX properties.
5253
final ComponentBase<ColorChooserState> componentBase = new ComponentBase<>(this, initialData, ColorChooserUpdater::update, new LoggingMiddleware<>());
5354

54-
// Setup the ReduxFX-view passing the view-function and this as the root node for the generated Scenegraph
55-
final ReduxFXView<ColorChooserState> view = ReduxFXView.create(ColorChooserView::view, this);
56-
57-
// Connect componentBase and view
58-
view.connect(componentBase.getStatePublisher(), componentBase.createActionSubscriber());
55+
// Setup the ReduxFX-view passing the component-base the view-function and this as the root node for the generated Scenegraph
56+
ReduxFXView.create(componentBase, ColorChooserView::view, this);
5957

6058
// This sets up the JavaFX property of this component. The value can be changed by dispatching
6159
// ObjectChangedCommands in the ColorChooserUpdater (alongside any required state changes). The VChangeListener

examples/colorchooser/src/main/java/com/netopyr/reduxfx/examples/colorchooser/component/updater/ColorChooserUpdater.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.netopyr.reduxfx.examples.colorchooser.component.actions.UpdateGreenAction;
99
import com.netopyr.reduxfx.examples.colorchooser.component.actions.UpdateRedAction;
1010
import com.netopyr.reduxfx.examples.colorchooser.component.state.ColorChooserState;
11+
import com.netopyr.reduxfx.store.Driver;
1112
import com.netopyr.reduxfx.updater.Update;
1213
import javafx.scene.paint.Color;
1314

@@ -27,7 +28,7 @@
2728
* action and calculates the new state from that.
2829
* <p>
2930
* Optionally it can also create an arbitrary number of commands, which are processed by a
30-
* {@link com.netopyr.reduxfx.driver.Driver}. Usually such a {@code Driver} has to be registered with the
31+
* {@link Driver}. Usually such a {@code Driver} has to be registered with the
3132
* {@link com.netopyr.reduxfx.store.ReduxFXStore}-instance explicitly, but {@code ColorChooserComponent} uses a
3233
* {@link ComponentBase} which registers a driver for component-specific commands and actions automatically.
3334
* See {@link ColorChooserComponent} for more details.

examples/external-store/pom.xml

-46
This file was deleted.

examples/external-store/src/main/java/com/netopyr/reduxfx/examples/externalstore/ExternalStore.java

-49
This file was deleted.

examples/external-store/src/main/java/com/netopyr/reduxfx/examples/externalstore/actions/Actions.java

-43
This file was deleted.

examples/external-store/src/main/java/com/netopyr/reduxfx/examples/externalstore/actions/IncCounterAction.java

-24
This file was deleted.

examples/external-store/src/main/java/com/netopyr/reduxfx/examples/externalstore/actions/InitAction.java

-24
This file was deleted.

examples/external-store/src/main/java/com/netopyr/reduxfx/examples/externalstore/reducer/Reducer.java

-63
This file was deleted.

0 commit comments

Comments
 (0)