Skip to content

0.2.0

Compare
Choose a tag to compare
@davidmarne davidmarne released this 13 Oct 04:20
· 39 commits to master since this release

Rather than implementing StoreConnector & StoreConnectorState you now only have to have to write one object that implements connect & build. The build function also now takes the mapped state value and actions as parameters.

abstract class MyWidgetProps implements Built<MyWidgetProps, MyWidgetPropsBuilder> {
  String get propIWantFromMyReduxState;
  MyWidgetProps._();
  factory MyWidgetProps([updates(MyWidgetPropsBuilder b)]) => _$MyWidgetProps;
}

class MyWidget extends StoreConnector<MyReduxState, MyReduxStateBuilder, MyReduxStateActions,
    MyWidgetProps, MyWidgetPropsBuilder> {
  MyWidget({Key key}) : super(key: key);

  @override
  MyWidgetProps connect(Store<MyReduxState, MyReduxStateBuilder, MyReduxStateActions> store) =>
      new MyWidgetProps((b) => b..propIWantFromMyReduxState = store.state.someProperty)

  MyWidgetState createState() => new MyWidgetState();
}

class MyWidgetState extends StoreConnectorState<MyReduxState, MyReduxStateBuilder,
    MyReduxStateActions, MyWidgetProps, MyWidgetPropsBuilder> {

  Widget build(BuildContext context) {
    return new Center(
      child: new Text(state.propIWantFromMyReduxState),
    );
  }

would now be

abstract class MyWidgetProps implements Built<MyWidgetProps, MyWidgetPropsBuilder> {
  String get propIWantFromMyReduxState;
  MyWidgetProps._();
  factory MyWidgetProps([updates(MyWidgetPropsBuilder b)]) => _$MyWidgetProps;
}

class MyWidget extends StoreConnector<MyReduxState, MyReduxStateBuilder, MyReduxStateActions, MyWidgetProps> {
  MyWidget({Key key}) : super(key: key);

  @override
  MyWidgetProps connect(MyReduxState state) =>
      new MyWidgetProps((b) => b..propIWantFromMyReduxState = state.someProperty);

  Widget build(BuildContext context, MyWidgetProps state, MyReduxStateActions actions) {
    return new Center(
      child: new Text(state.propIWantFromMyReduxState),
    );
  }