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

Additional Flow Checking? #20

Open
stratospark opened this issue May 26, 2016 · 7 comments
Open

Additional Flow Checking? #20

stratospark opened this issue May 26, 2016 · 7 comments

Comments

@stratospark
Copy link

What are some other ways to take advantage of static types?

  • Exhaustive pattern match cases on the Updater/Reducer so we make sure to handle each type?
  • Type checking the Views so that only explicitly declared Action types can be dispatched
  • ...

Are any of these possible?

I am trying to evaluate the state of Redux/Flow integration. I've seen this tutorial that provides stronger type checking: http://dchambers.github.io/articles/redux-flow-tutorial/. However, I see the value in the fractal components of redux-elm.

@tomkis
Copy link
Contributor

tomkis commented May 27, 2016

Not sure if you saw redux-elm examples using flow, you can find them in redux-elm-skeleton/examples-flow

Frankly, we are always using redux-elm with Flow and we are getting pretty close to Elm compiling experience. Unfortunately, docs are already overcomplicated for some people and therefore involving Flow would simply be way too much.

But the idea is that people should use Flow

Anyway, back to your questions:

Exhaustive pattern match cases on the Updater/Reducer so we make sure to handle each type?

I've been trying to solve this for quite a long time since this would be super cool and unfortunately came to a conclusion that this is simply not possible (definitely not with some drawbacks).

Type checking the Views so that only explicitly declared Action types can be dispatched

That would be definitely cool too, and IMO also probably doable as we could potentially make view wrapper generic - accepting action type union

...

So far, our support is limited to typed Models, we'd like to change this and support typed actions too - need to investigate more though.

@jmatsushita
Copy link

+1 to including typed Actions in the way proposed in the tutorial!

@tomkis
Copy link
Contributor

tomkis commented Jul 18, 2016

@ryyppy could shed some light onto this, especially how much possible would it be to have type checked view wrapper.

eg.

type IncrementAction = {
  type: 'Increment'
};

type DecrementAction = {
  type: 'Decrement'
};

type CounterActions = IncrementAction | DecrementAction;

const Counter : view<CounterActions> = view(({ dispatch }) => (
  <div>
    <button onClick={() => dispatch({ type: 'Increment' })}>Increment</button>
    <button onClick={() => dispatch({ type: 'Decrement' })}>Decrement</button>
    <button onClick={() => dispatch({ type: 'NonExistingAction' })}>Should raise an error</button>
  </div>
));

@ryyppy
Copy link

ryyppy commented Jul 19, 2016

I will have a look into that as soon as I find time this week... but I am sure there is an elegant solution. (also I wanted to take a look into your build system on how you distribute your flow types)

@ryyppy
Copy link

ryyppy commented Aug 5, 2016

Okay, I kinda forget to do anything here, but there are currently some interesting flow PRs pending, making it very easy to create .js.flow files of existing dist files (facebook/flow#2184) ... also I was not sure how and when your major changes to this project will take effect (project renaming etc.). Any thoughts on that?

Doesn't make any sense to flow type stuff which is changed very soon anyways :-)

@tomkis
Copy link
Contributor

tomkis commented Aug 5, 2016

@ryyppy facebook/flow#2184 is supercool, this will help us a lot with proper typing.

I am currently in the middle of quite complex rewrite and separation of concerns, so it would probably make sense to wait until version 3.x is released.

@tomkis
Copy link
Contributor

tomkis commented Feb 23, 2017

After major v4 rewrite, we have decided to re-write the library in TypeScript, so typings are also included and library should be fully-typed.

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

4 participants