Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: lib/src/change_notifier.dart

Issue 1616953004: Fixed strong mode errors and warnings reachable from lib/observe.dart (Closed) Base URL: https://github.com/dart-lang/observe.git@master
Patch Set: Removed inferrable type param Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/bind_property.dart ('k') | lib/src/change_record.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library observe.src.change_notifier; 5 library observe.src.change_notifier;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection' show UnmodifiableListView; 8 import 'dart:collection' show UnmodifiableListView;
9 import 'package:observe/observe.dart'; 9 import 'package:observe/observe.dart';
10 import 'package:observe/src/observable.dart' show notifyPropertyChangeHelper; 10 import 'package:observe/src/observable.dart' show notifyPropertyChangeHelper;
11 11
12 /// Mixin and base class for implementing an [Observable] object that performs 12 /// Mixin and base class for implementing an [Observable] object that performs
13 /// its own change notifications, and does not need to be considered by 13 /// its own change notifications, and does not need to be considered by
14 /// [Observable.dirtyCheck]. 14 /// [Observable.dirtyCheck].
15 /// 15 ///
16 /// When a field, property, or indexable item is changed, a derived class should 16 /// When a field, property, or indexable item is changed, a derived class should
17 /// call [notifyPropertyChange]. See that method for an example. 17 /// call [notifyPropertyChange]. See that method for an example.
18 abstract class ChangeNotifier implements Observable { 18 abstract class ChangeNotifier implements Observable {
19 StreamController _changes; 19 StreamController<List<ChangeRecord>> _changes;
20 List<ChangeRecord> _records; 20 List<ChangeRecord> _records;
21 21
22 Stream<List<ChangeRecord>> get changes { 22 Stream<List<ChangeRecord>> get changes {
23 if (_changes == null) { 23 if (_changes == null) {
24 _changes = new StreamController.broadcast(sync: true, 24 _changes = new StreamController.broadcast(
25 onListen: observed, onCancel: unobserved); 25 sync: true, onListen: observed, onCancel: unobserved);
26 } 26 }
27 return _changes.stream; 27 return _changes.stream;
28 } 28 }
29 29
30 // TODO(jmesserly): should these be public? They're useful lifecycle methods 30 // TODO(jmesserly): should these be public? They're useful lifecycle methods
31 // for subclasses. Ideally they'd be protected. 31 // for subclasses. Ideally they'd be protected.
32 /// Override this method to be called when the [changes] are first observed. 32 /// Override this method to be called when the [changes] are first observed.
33 void observed() {} 33 void observed() {}
34 34
35 /// Override this method to be called when the [changes] are no longer being 35 /// Override this method to be called when the [changes] are no longer being
(...skipping 23 matching lines...) Expand all
59 /// equal, no change will be recorded. 59 /// equal, no change will be recorded.
60 /// 60 ///
61 /// For convenience this returns [newValue]. This makes it easy to use in a 61 /// For convenience this returns [newValue]. This makes it easy to use in a
62 /// setter: 62 /// setter:
63 /// 63 ///
64 /// var _myField; 64 /// var _myField;
65 /// @reflectable get myField => _myField; 65 /// @reflectable get myField => _myField;
66 /// @reflectable set myField(value) { 66 /// @reflectable set myField(value) {
67 /// _myField = notifyPropertyChange(#myField, _myField, value); 67 /// _myField = notifyPropertyChange(#myField, _myField, value);
68 /// } 68 /// }
69 notifyPropertyChange(Symbol field, Object oldValue, Object newValue) 69 /*=T*/ notifyPropertyChange /*<T>*/ (
70 => notifyPropertyChangeHelper(this, field, oldValue, newValue); 70 Symbol field, /*=T*/ oldValue, /*=T*/ newValue) =>
71 notifyPropertyChangeHelper /*<T>*/ (this, field, oldValue, newValue);
71 72
72 void notifyChange(ChangeRecord record) { 73 void notifyChange(ChangeRecord record) {
73 if (!hasObservers) return; 74 if (!hasObservers) return;
74 75
75 if (_records == null) { 76 if (_records == null) {
76 _records = []; 77 _records = [];
77 scheduleMicrotask(deliverChanges); 78 scheduleMicrotask(deliverChanges);
78 } 79 }
79 _records.add(record); 80 _records.add(record);
80 } 81 }
81 } 82 }
OLDNEW
« no previous file with comments | « lib/src/bind_property.dart ('k') | lib/src/change_record.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698