ServiceList patch
This commit is contained in:
parent
cd199f2c8f
commit
c52a880489
3 changed files with 17 additions and 10 deletions
|
@ -1,2 +1,5 @@
|
||||||
|
# 1.1.0+2
|
||||||
|
* Updated `ServiceList` to also fire on `index`.
|
||||||
|
|
||||||
# 1.1.0+1
|
# 1.1.0+1
|
||||||
Added `ServiceList`.
|
* Added `ServiceList`.
|
|
@ -152,11 +152,18 @@ class ServiceList extends DelegatingList {
|
||||||
final StreamController<ServiceList> _onChange = new StreamController();
|
final StreamController<ServiceList> _onChange = new StreamController();
|
||||||
final List<StreamSubscription> _subs = [];
|
final List<StreamSubscription> _subs = [];
|
||||||
|
|
||||||
ServiceList(this.service, {this.idField, this.asPaginated: false, this.compare}) : super([]) {
|
ServiceList(this.service,
|
||||||
|
{this.idField, this.asPaginated: false, this.compare})
|
||||||
|
: super([]) {
|
||||||
// Index
|
// Index
|
||||||
_subs.add(service.onIndexed.listen((data) {
|
_subs.add(service.onIndexed.listen((data) {
|
||||||
var items = asPaginated == true ? data['data'] : data;
|
var items = asPaginated == true ? data['data'] : data;
|
||||||
this..clear()..addAll(items);
|
if (items.isNotEmpty) {
|
||||||
|
this
|
||||||
|
..clear()
|
||||||
|
..addAll(items);
|
||||||
|
_onChange.add(this);
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Created
|
// Created
|
||||||
|
@ -170,13 +177,11 @@ class ServiceList extends DelegatingList {
|
||||||
var indices = <int>[];
|
var indices = <int>[];
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
if (compareItems(item, this[i]))
|
if (compareItems(item, this[i])) indices.add(i);
|
||||||
indices.add(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indices.isNotEmpty) {
|
if (indices.isNotEmpty) {
|
||||||
for (var i in indices)
|
for (var i in indices) this[i] = item;
|
||||||
this[i] = item;
|
|
||||||
|
|
||||||
_onChange.add(this);
|
_onChange.add(this);
|
||||||
}
|
}
|
||||||
|
@ -202,8 +207,7 @@ class ServiceList extends DelegatingList {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compareItems(a, b) {
|
bool compareItems(a, b) {
|
||||||
if (compare != null)
|
if (compare != null) return compare(a, b);
|
||||||
return compare(a, b);
|
|
||||||
if (a is Map)
|
if (a is Map)
|
||||||
return a[idField ?? 'id'] == b[idField ?? 'id'];
|
return a[idField ?? 'id'] == b[idField ?? 'id'];
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_client
|
name: angel_client
|
||||||
version: 1.1.0+1
|
version: 1.1.0+2
|
||||||
description: Client library for the Angel framework.
|
description: Client library for the Angel framework.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/angel_client
|
homepage: https://github.com/angel-dart/angel_client
|
||||||
|
|
Loading…
Reference in a new issue