From c52a88048900e829d57a6f3a948a606a5d8427fd Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 13 Dec 2017 01:35:08 -0500 Subject: [PATCH] ServiceList patch --- CHANGELOG.md | 5 ++++- lib/angel_client.dart | 20 ++++++++++++-------- pubspec.yaml | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d97c937c..5b8a0acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,5 @@ +# 1.1.0+2 +* Updated `ServiceList` to also fire on `index`. + # 1.1.0+1 -Added `ServiceList`. \ No newline at end of file +* Added `ServiceList`. \ No newline at end of file diff --git a/lib/angel_client.dart b/lib/angel_client.dart index e65a578d..0464caf9 100644 --- a/lib/angel_client.dart +++ b/lib/angel_client.dart @@ -152,11 +152,18 @@ class ServiceList extends DelegatingList { final StreamController _onChange = new StreamController(); final List _subs = []; - ServiceList(this.service, {this.idField, this.asPaginated: false, this.compare}) : super([]) { + ServiceList(this.service, + {this.idField, this.asPaginated: false, this.compare}) + : super([]) { // Index _subs.add(service.onIndexed.listen((data) { var items = asPaginated == true ? data['data'] : data; - this..clear()..addAll(items); + if (items.isNotEmpty) { + this + ..clear() + ..addAll(items); + _onChange.add(this); + } })); // Created @@ -170,13 +177,11 @@ class ServiceList extends DelegatingList { var indices = []; for (int i = 0; i < length; i++) { - if (compareItems(item, this[i])) - indices.add(i); + if (compareItems(item, this[i])) indices.add(i); } if (indices.isNotEmpty) { - for (var i in indices) - this[i] = item; + for (var i in indices) this[i] = item; _onChange.add(this); } @@ -202,8 +207,7 @@ class ServiceList extends DelegatingList { } bool compareItems(a, b) { - if (compare != null) - return compare(a, b); + if (compare != null) return compare(a, b); if (a is Map) return a[idField ?? 'id'] == b[idField ?? 'id']; else diff --git a/pubspec.yaml b/pubspec.yaml index 7b2512ec..0b3adafb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_client -version: 1.1.0+1 +version: 1.1.0+2 description: Client library for the Angel framework. author: Tobe O homepage: https://github.com/angel-dart/angel_client