Skip to content

Commit

Permalink
Extract common method loadSuccess
Browse files Browse the repository at this point in the history
  • Loading branch information
shoothzj committed Aug 2, 2021
1 parent 7b9170b commit 97eccf1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
6 changes: 6 additions & 0 deletions lib/vm/base_load_list_page_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ abstract class BaseLoadListPageViewModel<T> extends DataTableSource {
this.converter = converter;
}

/// call loadSuccess to set loading to false and clear the exceptions
void loadSuccess() {
loading = false;
loadException = null;
}

@override
DataRow? getRow(int index) {
if (converter == null) {
Expand Down
6 changes: 6 additions & 0 deletions lib/vm/base_load_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ class BaseLoadViewModel extends ChangeNotifier {
Exception? loadException;

Exception? opException;

/// call loadSuccess to set loading to false and clear the exceptions
void loadSuccess() {
loading = false;
loadException = null;
}
}
3 changes: 1 addition & 2 deletions lib/vm/pulsar/pulsar_instance_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class PulsarInstanceViewModel
.map((e) => PulsarTenantViewModel(pulsarInstancePo, e))
.toList();
this.displayList = this.fullList;
loadException = null;
loading = false;
loadSuccess();
} on Exception catch (e) {
log('request failed, $e');
loadException = e;
Expand Down
3 changes: 1 addition & 2 deletions lib/vm/pulsar/pulsar_namespace_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class PulsarNamespaceViewModel
pulsarInstancePo, tenantResp, namespaceResp, e))
.toList();
this.displayList = this.fullList;
loadException = null;
loading = false;
loadSuccess();
} on Exception catch (e) {
loadException = e;
loading = false;
Expand Down
3 changes: 1 addition & 2 deletions lib/vm/pulsar/pulsar_partitioned_topic_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class PulsarTopicViewModel extends BaseLoadListViewModel<SubscriptionResp> {
host, port, tenant, namespace, topic);
this.fullList = results;
this.displayList = this.fullList;
loadException = null;
loading = false;
loadSuccess();
} on Exception catch (e) {
loadException = e;
loading = false;
Expand Down
3 changes: 1 addition & 2 deletions lib/vm/pulsar/pulsar_tenant_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class PulsarTenantViewModel
.map((e) => PulsarNamespaceViewModel(pulsarInstancePo, tenantResp, e))
.toList();
this.displayList = this.fullList;
loadException = null;
loading = false;
loadSuccess();
} on Exception catch (e) {
loadException = e;
loading = false;
Expand Down

0 comments on commit 97eccf1

Please sign in to comment.