Skip to content
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

Problem with ReduxFX.start and Bifunction #49

Closed
renanliberato opened this issue Jun 17, 2017 · 1 comment
Closed

Problem with ReduxFX.start and Bifunction #49

renanliberato opened this issue Jun 17, 2017 · 1 comment

Comments

@renanliberato
Copy link

Hello,

I'm trying to implement an example with ReduxFX but I have a problem that is keeping me from using this project.

Here's an example:

@Override
    public void start(Stage mainStage) throws Exception {
        final AppState initialState = AppState.create();

        ReduxFX.start(
            initialState,
            IncrementReducer::update,
            HomeView::view,
            mainStage);
    }
public class HomeView {

    public static VNode view(AppState state) {
        Objects.requireNonNull(state, "The parameter 'state' must not be null");

        return Stage().....;
    }
}
public class IncrementReducer {


    public static 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 Javaslang'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(

                // If the action is a IncCounterAction, we return a new AppState with an increased counter
                Case(instanceOf(IncrementReducer.class),
                        incCounterAction -> state.withCounter(state.getCounter() + 1)
                ),

                // 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)
        );
    }
}

The Intellij hint gives me this alert Cannot resolve method 'start(com.renanliberato.app.state.AppState, <method reference>, <method reference>, javafx.stage.Stage)' and if I try to run it, it gives me this error:

Error:(28, 16) java: no suitable method found for start(com.renanliberato.app.state.AppState,IncrementR[...]pdate,HomeView::view,javafx.stage.Stage)
    method com.netopyr.reduxfx.ReduxFX.<STATE>start(STATE,java.util.function.BiFunction<STATE,java.lang.Object,com.netopyr.reduxfx.updater.Update<STATE>>,java.util.function.Function<STATE,com.netopyr.reduxfx.vscenegraph.VNode>,javafx.stage.Stage) is not applicable
      (cannot infer type-variable(s) STATE
        (argument mismatch; bad return type in method reference
          com.renanliberato.app.state.AppState cannot be converted to com.netopyr.reduxfx.updater.Update<STATE>))
    method com.netopyr.reduxfx.ReduxFX.<STATE>start(STATE,java.util.function.BiFunction<STATE,java.lang.Object,com.netopyr.reduxfx.updater.Update<STATE>>,java.util.function.Function<STATE,com.netopyr.reduxfx.vscenegraph.VNode>,javafx.scene.Group) is not applicable
      (cannot infer type-variable(s) STATE
        (argument mismatch; bad return type in method reference
          com.renanliberato.app.state.AppState cannot be converted to com.netopyr.reduxfx.updater.Update<STATE>))
    method com.netopyr.reduxfx.ReduxFX.<STATE>start(STATE,java.util.function.BiFunction<STATE,java.lang.Object,com.netopyr.reduxfx.updater.Update<STATE>>,java.util.function.Function<STATE,com.netopyr.reduxfx.vscenegraph.VNode>,javafx.scene.layout.Pane) is not applicable
      (cannot infer type-variable(s) STATE
        (argument mismatch; bad return type in method reference
          com.renanliberato.app.state.AppState cannot be converted to com.netopyr.reduxfx.updater.Update<STATE>))

In my pom.xml file I've imported this dependency, as included in the README.md:

<dependency>
    <groupId>com.netopyr.reduxfx</groupId>
    <artifactId>reduxfx</artifactId>
    <version>0.3.1</version>
</dependency>

I'd appreciate to know if this is some misunderstanding that I've made with Bifunction or anything else, because this may be an example of problems someone who didn't know this project may run when trying to implement it.

Will it help if I submit a gist with a more complete code example?

@netopyr
Copy link
Owner

netopyr commented Jun 18, 2017

Hi renanliberato,

thanks for trying out ReduxFX. I think you need to switch to the class SimpleReduxFX instead of ReduxFX (in the same package). Otherwise your code looks fine.

SimpleReduxFX gives you everything you need to implement your first examples and simple demos. But when you try to implement a real application, you will realize that one important piece is missing: SimpleReduxFX lacks the ability to communicate with anything that is not UI, e.g. servers, file-system etc. The class ReduxFX adds the missing functionality, but you have to return an instance of Update instead of the new state. Update contains the new state and an arbitrary list of commands, which are used to communicate with the outside world. You can find some more details here: https://github.com/netopyr/reduxfx/blob/master/doc/driver.md

Sorry that the documentation is not clear enough right now. Unfortunately the documentation is clearly one of the weak points at this point.

Cheers,
Michael

@netopyr netopyr closed this as completed Jul 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants