Skip to content

Commit

Permalink
support nullable action
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed Nov 28, 2020
1 parent 59087e1 commit cf15c0b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/src/redux_store_stream_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
Stream<S> bind(Stream<A> stream) {
late StreamController<S> controller;
List<StreamSubscription<dynamic>>? subscriptions;
StreamController<WrapperAction<A>>? _actionController;
StreamController<WrapperAction>? _actionController;

void onListen() {
S state;
Expand All @@ -101,7 +101,7 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
return;
}

void onDataActually(WrapperAction<A> wrapper) {
void onDataActually(WrapperAction wrapper) {
final type = wrapper.type;
final currentState = state;

Expand All @@ -114,7 +114,7 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
return controller.add(currentState);
}

final action = wrapper.action;
final action = wrapper.action<A>();
try {
final newState = _reducer(currentState, action);
controller.add(newState);
Expand Down Expand Up @@ -144,7 +144,7 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
}

final actionController =
_actionController = StreamController<WrapperAction<A>>.broadcast();
_actionController = StreamController<WrapperAction>.broadcast();

// Call reducer on each action.
final subscriptionActionController =
Expand All @@ -163,7 +163,7 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {

final getState = () => state;
final actionStream = actionController.stream
.map((wrapper) => wrapper.action)
.map((wrapper) => wrapper.action<A>())
.asBroadcastStream(onCancel: (s) => s.cancel());

subscriptions = [
Expand Down Expand Up @@ -205,7 +205,7 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
}

Iterable<StreamSubscription<dynamic>> _listenSideEffects(
StreamController<WrapperAction<A>> actionController,
StreamController<WrapperAction> actionController,
GetState<S> getState,
StreamController<S> stateController,
Stream<A> actionStream,
Expand Down
10 changes: 5 additions & 5 deletions lib/src/wrapper_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ class _SideEffect extends ActionType {
_SideEffect(this.index) : super._empty();
}

class WrapperAction<A> {
class WrapperAction {
final dynamic _action;
final ActionType type;

const WrapperAction._(this._action, this.type);

factory WrapperAction.external(A action) =>
factory WrapperAction.external(dynamic action) =>
WrapperAction._(action, ActionType._external);

factory WrapperAction.sideEffect(A action, int index) =>
factory WrapperAction.sideEffect(dynamic action, int index) =>
WrapperAction._(action, ActionType._sideEffect(index));

static const initial = WrapperAction<Never>._(null, ActionType._initial);
static const initial = WrapperAction._(null, ActionType._initial);

A get action {
A action<A>() {
if (identical(this, initial)) {
throw StateError('Cannot get action from WrapperAction.initial');
}
Expand Down

0 comments on commit cf15c0b

Please sign in to comment.