Modules

Defining a module

class CartModule extends Module {
  @override
  String get name => 'cart';

  final Map<String, dynamic> state = {
    'fetchingItems': false,
    'items': [],
  };

  final List<Getter> getters = [
    IsCartEmptyGetter(),
    IsFetchingGetter(),
  ];

  final List<Mutation> mutations = [
    UpdateCartItemsMutation(),
    UpdateFetchingStatusMutation(),
  ];

  final List<Action> actions = [
    FetchCartItemsAction(),
  ];
}

Registering the module

class MyStore extends Store {
  MyStore() : super(
    Module(
      modules: [
        CartModule(),
      ]
    ),
  );
}

Using features from the module

All the features can be used as quite as the previously ones, the unique difference now, is that you need to pass the namespace as prefix. Your namespace will be the path for your module

store.getter('/cart/isEmpty');

Last updated