brianegan / flutter_redux

A library that connects Widgets to a Redux Store
MIT License
1.65k stars 219 forks source link

Import Store data type #230

Open hummy123 opened 2 years ago

hummy123 commented 2 years ago

Hi there,

First of all, thank you for the wonderful tool. I like it even more than the original JS Redux ,with the support for enums for actions and with Dart's strong typing which allows code suggestions while typing.

The one request I have is about exposing the Store class used with Redux so it can be imported. I will try to show the code that I currently have after mentioning these benefits I see from doing this.

  1. Can pass store as a function parameter with strong typing. (If I try passing a store as a function parameter now, it has to be of type dynamic which can break depending on other developers.
  2. Better code suggestions from IDE compared to using type dynamic.

I hope that makes sense. Thanks for your time, and once again, for my favourite way of managing state with Flutter.

PS: Side question I hope you don't mind.

If I have multiple forms that I would like to use Redux for, is it better to have:

  1. An ephemeral store for each form separate from the global app state (possibly a better memory optimisation, at the cost of architectural complexity), or
  2. A single global app state with each form data class being nullable and set to null once the form data has been submitted.

EDIT: I have a function like this, which is called in a loop.

double calculateDistanceFromUser(dynamic store, LatLng inputPoints) {
  const Distance geo = Distance();
  return geo.as(
    LengthUnit.Kilometer,
    inputPoints,
    LatLng(
      store.state.userLocation.latitude,
      store.state.userLocation.longitude,
    ),
  );
}

My two choices are to look up the store from the build context each loop iteration (unnecessary computation) or to use type dynamic to represent the store, neither of which is desirable.