Skip to content

Commit

Permalink
Merge pull request alibaba#554 from Wanchen7/develop
Browse files Browse the repository at this point in the history
add defaultWidget option for buildComponent
  • Loading branch information
zjuwjf committed Dec 10, 2019
2 parents 2332402 + 1e4fecf commit 28f247a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/src/redux_component/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ abstract class ViewService implements ExtraData {
ListAdapter buildAdapter();

/// The way to build slot component which is configured in Dependencies.slots
Widget buildComponent(String name);
Widget buildComponent(String name,{Widget defaultWidget});

/// Get BuildContext from the host-widget
BuildContext get context;
Expand Down
9 changes: 5 additions & 4 deletions lib/src/redux_component/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ abstract class LogicContext<T> extends ContextSys<T> with _ExtraMixin {
dynamic dispatch(Action action) => _dispatch(action);

@override
Widget buildComponent(String name) {
Widget buildComponent(String name,{Widget defaultWidget}) {
assert(name != null, 'The name must be NotNull for buildComponent.');
final Dependent<T> dependent = logic.slot(name);
final Widget result = dependent?.buildComponent(store, getState,
bus: bus, enhancer: enhancer);
assert(result != null, 'Could not found component by name "$name."');
return result ?? Container();
assert(result != null || defaultWidget != null,
'Could not found component by name "$name." You can set a default widget for buildComponent');
return result ?? (defaultWidget ?? Container());
}

@override
Expand Down Expand Up @@ -280,7 +281,7 @@ class PureViweViewService implements ViewService {
'Unexpected call of "buildAdapter" in a PureViewComponent');

@override
Widget buildComponent(String name) => throw Exception(
Widget buildComponent(String name,{Widget defaultWidget}) => throw Exception(
'Unexpected call of "buildComponent" in a PureViewComponent');

@override
Expand Down

0 comments on commit 28f247a

Please sign in to comment.