alibaba / fish-redux

An assembled flutter application framework.
https://github.com/alibaba/fish-redux
Apache License 2.0
7.33k stars 843 forks source link

adapter中的component,始终收不到自己的reducer事件 #621

Closed luckysmg closed 4 years ago

luckysmg commented 4 years ago

我检查了我代码应该没有问题,无论是通过直接在view里面dispatch还是在effect里面再dispatch过去都收不到,在adapter里面

class HomeAdapter extends SourceFlowAdapter<HomeState> {
  HomeAdapter()
      : super(
          pool: <String, Component<Object>>{"item": ListComponent()},
        );
}

其中的Item部分: action:

enum ListAction {
  update,
  onUpdate,
}

class ListActionCreator {
  static Action update() {
    return const Action(ListAction.update);
  }

  static Action onUpdate() {
    return const Action(ListAction.onUpdate);
  }
}

effect:

Effect<ListState> buildEffect() {
  return combineEffects(<Object, Effect<ListState>>{
    ListAction.onUpdate: _onUpdate,
  });
}

void _onUpdate(Action action, Context<ListState> ctx) {
  print('effect');
  ctx.dispatch(ListActionCreator.update());
}

reducer:

Reducer<ListState> buildReducer() {
  return asReducer(
    <Object, Reducer<ListState>>{
      ListAction.update: _update,
    },
  );
}

ListState _update(ListState state, Action action) {
  print('reducer');
  final ListState newState = state.clone();
  return newState;
}

state:

class ListState implements Cloneable<ListState> {
  String item;

  @override
  ListState clone() {
    return ListState()..item = item;
  }
}

view

Widget buildView(ListState state, Dispatch dispatch, ViewService viewService) {
  return GestureDetector(
    onTap: () {
      dispatch(ListActionCreator.onUpdate());
    },
    child: Center(
      child: Padding(
        padding: EdgeInsets.all(10),
        child: Text(state.item, style: TextStyle(fontSize: 30)),
      ),
    ),
  );
}

点击后打印出来的内容: flutter: effect

结果,reducer没有看到。目前我测试了一下adapter里面出现了接收不到。其他没问题

luckysmg commented 4 years ago

解决了,effect的中间件影响了