Skip to content

There should be a way to refer to the Store without a reference to the Builder #137

@dalewking

Description

@dalewking

Looking at the example in flutter_built_redux we see this:

class ConnectionExample extends StatelessWidget {
  final Store<Counter, CounterBuilder, CounterActions> store;

I have a problem with this in that it is exposing internal details of the Counter class in the UI. The UI should not know anything about the existence of CounterBuilder. I don't even like having the UI know about the concrete Counter class and would declare an abstract class defining the interface the UI cares about (since there may internal parts of the state that is not exposed to the UI). So for the example let's say we declare this class that Counter implements:

abstract class CounterApi {
  int get count;
}

The UI should only depend on this interface. With the normal version of redux you can easily refer to a Store<Counter> as a Store<CounterApi>, but we cannot do the equivalent with built_redux because the Store type has 3 type parameters now. The actions parameter is fine, but the Builder parameter is problematic.

So what is the solution? I understand that the Builder type is vital on actually creating the store but it is not necessary for users of the store, they only need state and actions. So the most likely solution is for you to refactor a super interface for Store:

abstract class StoreApi<State, Actions extends ReduxActions> {
  /// [state] returns the current state
  State get state;

  /// [actions] returns the synced actions
  Actions get action;

  /// [nextState] is a stream which has a payload of the next state value
  Stream<State> get nextState => stream
}

This will let you refer to the store using a variable of type StoreApi<CounterApi, CounterActions>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions