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

Import Store data type #230

Open
hummy123 opened this issue Apr 9, 2022 · 0 comments
Open

Import Store data type #230

hummy123 opened this issue Apr 9, 2022 · 0 comments

Comments

@hummy123
Copy link

hummy123 commented Apr 9, 2022

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.

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

1 participant