Showing
2 changed files
with
39 additions
and
0 deletions
| @@ -73,6 +73,18 @@ class RxList<E> extends ListMixin<E> | @@ -73,6 +73,18 @@ class RxList<E> extends ListMixin<E> | ||
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | @override | 75 | @override |
| 76 | + void removeWhere(bool test(E element)) { | ||
| 77 | + _value.removeWhere(test); | ||
| 78 | + refresh(); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @override | ||
| 82 | + void retainWhere(bool test(E element)) { | ||
| 83 | + _value.retainWhere(test); | ||
| 84 | + refresh(); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @override | ||
| 76 | int get length => value.length; | 88 | int get length => value.length; |
| 77 | 89 | ||
| 78 | @override | 90 | @override |
| @@ -162,4 +162,31 @@ void main() { | @@ -162,4 +162,31 @@ void main() { | ||
| 162 | expect(reactiveString.endsWith("c"), true); | 162 | expect(reactiveString.endsWith("c"), true); |
| 163 | expect(currentString, "abc"); | 163 | expect(currentString, "abc"); |
| 164 | }); | 164 | }); |
| 165 | + | ||
| 166 | + test('Number of times "ever" is called in RxList', () async { | ||
| 167 | + final list = [1, 2, 3].obs; | ||
| 168 | + var count = 0; | ||
| 169 | + ever<List<int>>(list, (value) { | ||
| 170 | + count++; | ||
| 171 | + }); | ||
| 172 | + | ||
| 173 | + list.add(4); | ||
| 174 | + await Future.delayed(Duration.zero); | ||
| 175 | + expect(count, 1); | ||
| 176 | + | ||
| 177 | + count = 0; | ||
| 178 | + list.addAll([4, 5]); | ||
| 179 | + await Future.delayed(Duration.zero); | ||
| 180 | + expect(count, 1); | ||
| 181 | + | ||
| 182 | + count = 0; | ||
| 183 | + list.removeWhere((element) => element == 2); | ||
| 184 | + await Future.delayed(Duration.zero); | ||
| 185 | + expect(count, 1); | ||
| 186 | + | ||
| 187 | + count = 0; | ||
| 188 | + list.retainWhere((element) => element == 1); | ||
| 189 | + await Future.delayed(Duration.zero); | ||
| 190 | + expect(count, 1); | ||
| 191 | + }); | ||
| 165 | } | 192 | } |
-
Please register or login to post a comment