Skip to content

Commit

Permalink
Replaced createActionSubscriber() functionality with simple dispatch(…
Browse files Browse the repository at this point in the history
…)-methods.

Removed SimpleReduxFXStore.
Removed default drivers.
Removed functionality to attach ReduxFXView to 3rd-party store.
  • Loading branch information
netopyr committed Nov 13, 2017
1 parent 45b95a9 commit 1b76129
Show file tree
Hide file tree
Showing 47 changed files with 347 additions and 1,219 deletions.
4 changes: 4 additions & 0 deletions examples/colorchooser/pom.xml
Expand Up @@ -32,6 +32,10 @@
<groupId>com.netopyr.reduxfx</groupId>
<artifactId>reduxfx-view</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
</dependencies>

</project>
Expand Up @@ -4,7 +4,7 @@
import com.netopyr.reduxfx.examples.colorchooser.app.updater.Updater;
import com.netopyr.reduxfx.examples.colorchooser.app.view.MainView;
import com.netopyr.reduxfx.middleware.LoggingMiddleware;
import com.netopyr.reduxfx.store.SimpleReduxFXStore;
import com.netopyr.reduxfx.store.ReduxFXStore;
import com.netopyr.reduxfx.vscenegraph.ReduxFXView;
import javafx.application.Application;
import javafx.scene.paint.Color;
Expand All @@ -21,13 +21,10 @@ public void start(Stage primaryStage) throws Exception {
final AppState initialState = AppState.create().withColor(Color.VIOLET);

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

// Setup the ReduxFX-view passing the view-function and the primary stage that should hold the calculated view
final ReduxFXView<AppState> view = ReduxFXView.createStage(MainView::view, primaryStage);

// Connect store and view
view.connect(store.getStatePublisher(), store.createActionSubscriber());
// Setup the ReduxFX-view passing the store, the view-function and the primary stage that should hold the calculated view
ReduxFXView.createStage(store, MainView::view, primaryStage);
}

public static void main(String[] args) {
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.netopyr.reduxfx.examples.colorchooser.app.actions.UpdateColorAction;
import com.netopyr.reduxfx.examples.colorchooser.app.state.AppState;
import com.netopyr.reduxfx.updater.Update;

import java.util.Objects;

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

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

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

// This is the default branch of this switch-case. If an unknown action was passed to the
// updater, we simply return the old state. This is a convention, that is not needed right
// now, but will help once you start to decompose your updater.
Case($(), state)
// If the action is a UpdateColorAction, we return a new AppState with the
// property color set to the new value.
Case($(instanceOf(UpdateColorAction.class)),
updateColorAction -> state.withColor(updateColorAction.getValue())
),

// This is the default branch of this switch-case. If an unknown action was passed to the
// updater, we simply return the old state. This is a convention, that is not needed right
// now, but will help once you start to decompose your updater.
Case($(), state)
)
);
}
}
Expand Up @@ -8,6 +8,7 @@
import com.netopyr.reduxfx.component.ComponentBase;
import com.netopyr.reduxfx.examples.colorchooser.app.view.MainView;
import com.netopyr.reduxfx.middleware.LoggingMiddleware;
import com.netopyr.reduxfx.store.Driver;
import com.netopyr.reduxfx.vscenegraph.ReduxFXView;
import com.netopyr.reduxfx.vscenegraph.builders.Factory;
import javafx.beans.property.ObjectProperty;
Expand All @@ -20,7 +21,7 @@
*
* It extends {@code VBox} and adds one additional JavaFX property {@link #colorProperty()}. As usual in ReduxFX,
* we do not want to modify state directly and this also applies to JavaFX properties of the public interface.
* Instead we use a {@link com.netopyr.reduxfx.driver.Driver} for that. We can send commands to the driver to update
* Instead we use a {@link Driver} for that. We can send commands to the driver to update
* the value of the JavaFX property. Commands are created in the {@link ColorChooserUpdater} together with the state
* changes. If the value of a JavaFX property changes, our updater receives an action, which can be specified here.
*/
Expand All @@ -47,15 +48,12 @@ public ColorChooserComponent() {
// Setup the initial state
final ColorChooserState initialData = new ColorChooserState();

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

// Setup the ReduxFX-view passing the view-function and this as the root node for the generated Scenegraph
final ReduxFXView<ColorChooserState> view = ReduxFXView.create(ColorChooserView::view, this);

// Connect componentBase and view
view.connect(componentBase.getStatePublisher(), componentBase.createActionSubscriber());
// Setup the ReduxFX-view passing the component-base the view-function and this as the root node for the generated Scenegraph
ReduxFXView.create(componentBase, ColorChooserView::view, this);

// This sets up the JavaFX property of this component. The value can be changed by dispatching
// ObjectChangedCommands in the ColorChooserUpdater (alongside any required state changes). The VChangeListener
Expand Down
Expand Up @@ -8,6 +8,7 @@
import com.netopyr.reduxfx.examples.colorchooser.component.actions.UpdateGreenAction;
import com.netopyr.reduxfx.examples.colorchooser.component.actions.UpdateRedAction;
import com.netopyr.reduxfx.examples.colorchooser.component.state.ColorChooserState;
import com.netopyr.reduxfx.store.Driver;
import com.netopyr.reduxfx.updater.Update;
import javafx.scene.paint.Color;

Expand All @@ -27,7 +28,7 @@
* action and calculates the new state from that.
* <p>
* Optionally it can also create an arbitrary number of commands, which are processed by a
* {@link com.netopyr.reduxfx.driver.Driver}. Usually such a {@code Driver} has to be registered with the
* {@link Driver}. Usually such a {@code Driver} has to be registered with the
* {@link com.netopyr.reduxfx.store.ReduxFXStore}-instance explicitly, but {@code ColorChooserComponent} uses a
* {@link ComponentBase} which registers a driver for component-specific commands and actions automatically.
* See {@link ColorChooserComponent} for more details.
Expand Down
46 changes: 0 additions & 46 deletions examples/external-store/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 1b76129

Please sign in to comment.