Skip to content

Commit

Permalink
bump deps & public ObservableList spy
Browse files Browse the repository at this point in the history
  • Loading branch information
jodinathan committed Dec 4, 2024
1 parent 4fc2a3a commit 75b9539
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 1,758 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.25.0
* Bumped dependencies and SDK
* Made spy in ObservableList public

## 0.24.0

* Migrated to [null safety](https://dart.dev/null-safety).
Expand Down
10 changes: 0 additions & 10 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
include: package:lints/recommended.yaml

analyzer:
language:
strict-inference: true
strict-raw-types: true
strong-mode:
implicit-casts: false
implicit-dynamic: false

linter:
rules:
- avoid_dynamic_calls
- cancel_subscriptions
- hash_and_equals
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- test_types_in_equals
- unrelated_type_equality_checks
- valid_regexps
Expand Down
4 changes: 2 additions & 2 deletions lib/src/async/async.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library change_notifier.async;

export 'change_notifier.dart' show AsyncChangeNotifier, PropertyChangeNotifier;
export 'change_notifier.dart' show AsyncChangeNotifier, PropertyChangeNotifier,
ListenableIterable, ChangeStreamNotifier;
export 'differs.dart' show Differ, EqualityDiffer, ListDiffer, MapDiffer;
export 'observable.dart';
export 'observable_list.dart';
Expand All @@ -12,4 +13,3 @@ export 'records.dart'
ListChangeRecord,
MapChangeRecord,
PropertyChangeRecord;
export 'to_observable.dart';
26 changes: 24 additions & 2 deletions lib/src/async/change_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,35 @@ import 'internal.dart';
import 'observable.dart';
import 'records.dart';

abstract class ChangeStreamNotifier {
StreamController? _changes;
Stream get changes {
final ctrl = _changes ??= StreamController.broadcast(onCancel: () {
final cur = _changes;

_changes = null;
cur!.close();
});

return ctrl.stream;
}

@protected
void changed() {
_changes?.add(null);
}
}

abstract class ListenableIterable<T>
implements Iterable<T>, ChangeStreamNotifier {}

/// Supplies [changes] and various hooks to implement [Observable].
///
/// May use [notifyChange] to queue a change record; they are asynchronously
/// delivered at the end of the VM turn.
///
/// [AsyncChangeNotifier] may be extended, mixed in, or used as a delegate.
class AsyncChangeNotifier<C extends ChangeRecord> implements Observable<C> {
mixin AsyncChangeNotifier<C extends ChangeRecord> implements Observable<C> {
StreamController<List<C>>? _changes;

bool _scheduled = false;
Expand Down Expand Up @@ -97,7 +119,7 @@ class AsyncChangeNotifier<C extends ChangeRecord> implements Observable<C> {
/// [PropertyChangeNotifier] may be extended or used as a delegate. To use as
/// a mixin, instead use with [PropertyChangeMixin]:
/// with ChangeNotifier<PropertyChangeRecord>, PropertyChangeMixin
mixin PropertyChangeNotifier<K> implements AsyncChangeNotifier {
mixin PropertyChangeNotifier<K extends Object> implements AsyncChangeNotifier {
T notifyPropertyChange<T>(
K field,
T oldValue,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/async/observable_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ObservableList<E> extends ListBase<E>
/// and if all elements stored into the returned list are actually instance
/// of [S], then the returned list can be used as a `ObservableList<T>`.
static ObservableList<T> castFrom<S, T>(ObservableList<S> source) =>
ObservableList<T>._spy(source._list.cast<T>());
ObservableList<T>.spy(source._list.cast<T>());

List<ListChangeRecord<E>>? _listRecords;

Expand All @@ -45,7 +45,7 @@ class ObservableList<E> extends ListBase<E>
/// the list will be the order provided by the iterator of [other].
ObservableList.from(Iterable<E> other) : _list = List<E>.from(other);

ObservableList._spy(List<E> other) : _list = other;
ObservableList.spy(List<E> other) : _list = other;

/// Returns a view of this list as a list of [T] instances.
///
Expand Down Expand Up @@ -230,8 +230,8 @@ class ObservableList<E> extends ListBase<E>
// We are modifying the length just below these checks. Without the checks
// Array.copy could throw an exception, leaving the list in a bad state
// (with a length that has been increased, but without a new element).
if (index is! int) throw ArgumentError(index);
RangeError.checkValidIndex(index, this);

_list
// Increase the length by adding [element], in case [E] isn't nullable.
..add(element)
Expand Down
1 change: 0 additions & 1 deletion lib/src/async/observable_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'dart:collection';

import 'change_notifier.dart';
import 'records.dart';
import 'to_observable.dart';

// TODO(jmesserly): this needs to be faster. We currently require multiple
// lookups per key to get the old value.
Expand Down
116 changes: 0 additions & 116 deletions lib/src/async/to_observable.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/src/sync/change_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef VoidCallback = void Function();
/// * [InheritedNotifier], an abstract superclass for widgets that use a
/// [Listenable]'s notifications to trigger rebuilds in descendant widgets
/// that declare a dependency on them, using the [InheritedWidget] mechanism.
/// * [new Listenable.merge], which creates a [Listenable] that triggers
/// * [Listenable.merge], which creates a [Listenable] that triggers
/// notifications whenever any of a list of other [Listenable]s trigger their
/// notifications.
abstract class Listenable {
Expand Down
5 changes: 2 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name: change_notifier
version: 0.24.0
version: 0.25.0
description: Support for marking objects as observable
homepage: https://github.com/angulardart-community/change_notifier
environment:
sdk: '>=2.12.0 <=3.0.0'
sdk: '>=3.1.0 <=4.0.0'

dependencies:
collection: ^1.15.0
dart_internal: ^0.2.2
meta: ^1.7.0
quiver: ^3.0.1+1

Expand Down
103 changes: 0 additions & 103 deletions test/change_notifier_test.dart

This file was deleted.

Loading

0 comments on commit 75b9539

Please sign in to comment.