fluttercommunity / fluttercommunity/redux.dart

TypedReducer is not extendable

Open
#63 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
519
Forks
57
PR merge metrics
No merged PRs in 30d

Description

Current TypedReducer looks:

```dart
class TypedReducer implements ReducerClass {
/// A [Reducer] function that only accepts an action of a specific type
final State Function(State state, Action action) reducer;

/// Creates a reducer that will only be executed if the dispatched action
/// matches the [Action] type.
TypedReducer(this.reducer);

@override
State call(State state, dynamic action) {
if (action is Action) {
return reducer(state, action);
}

return state;
}
}
```

I prefer to extend TypedReducer instead pass function. It looks more convenient and by this reason I am using next version of TypedReducer:

```dart
abstract class TypedReducer implements ReducerClass {
factory TypedReducer(State Function(State state, Action action) reducer) =>
_TypedReducer(reducer);

TypedReducer.default();

@override
State call(State state, dynamic action) {
if (action is Action) {
return reduce(state, action);
}

return state;
}

State reduce(State state, Action action);
}

class _TypedReducer extends TypedReducer {
final State Function(State state, Action action) reducer;

_TypedReducer(this.reducer) : super.default();

@override
State reduce(State state, Action action) => reducer(state, action);
}

```
It doesn't make any conflict with current code and I think this version can be helpful for other users of this library.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.