redux_enhancement library
Redux Enhancement aims to provide an opiniotated approach for complex redux applications
For every class that is used within the state, a ReduxReducer is created. These classes can be infinitely nested, as long as every Action (classes that extend ReduxAction) has at maximum ONE reducer for every possible signature. Having multiple reducers will not produce errors, but the first that is found wins which will result in unexpected behaviour.
class Customer {
String name = '';
}
class AppState {
Customer customer = Customer();
}
class UpdateCustomerNameAction extends ReduxAction<String> {
UpdateCustomerNameAction(String value) : super(value);
}
class CustomerReducer extends ReduxReducer<AppState, Customer> {
CustomerReducer()
: super(
getter: (appStateBuilder) => appStateBuilder.customer,
setter: (appStateBuilder, customer) => appStateBuilder..customer = customer,
reducers: [
ActionReducer<Customer, UpdateCustomerNameAction, String>(_OnUpdateCustomerNameAction),
],
children: [],
);
static Customer _OnUpdateCustomerNameAction(Customer customer, String name) => customer..name = name;
}
class AppStateReducer extends ReduxReducer<AppState, AppState> {
AppStateReducer()
: super(
getter: (state) => state,
setter: (state, value) => value,
reducers: [],
children: [
CustomerReducer(),
],
);
}
Classes
-
ActionReducer<
State, Action, Value> -
Logical representation of an
Action
linked to a SetterFunction -
ReduxAction<
T> - Abstract class every Action that is used with this packages ReduxReducer must extend. Use the IDE to your advantage and let the constructor be auto-generated - less typing!
-
ReduxReducer<
Parent, ClassType> - Every Reducer has to extend this class
Functions
-
combineSetterFunctions<
Root, Intermediate, Value> (SetterFunction< Root, Intermediate> rootSetter, SetterFunction<Intermediate, Value> propertySetter, GetterFunction<Root, Intermediate> rootGetter) → SetterFunction<Root, Value> -
Root
- Type of the root object that will be changed
Typedefs
-
GetterFunction<
Type, Value> = Value Function(Type) -
Named Function Signature that takes an object of
Type
and returns a value ofValue
-
ReducerFunction<
Type, Value> = Type Function(Type, ReduxAction< Value> ) - Named Function Signature that is used within ReduxReducer.reducers
-
SetterFunction<
Type, Value> = Type Function(Type, Value) -
Named Function Signature that takes an object of
Type
and sets a property of typeValue