| OLD | NEW |
| 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 part of observe; | 5 part of observe; |
| 6 | 6 |
| 7 const _VALUE = const Symbol('value'); | 7 const _VALUE = const Symbol('value'); |
| 8 | 8 |
| 9 // Inspired by ArrayReduction at: | 9 // Inspired by ArrayReduction at: |
| 10 // https://raw.github.com/rafaelw/ChangeSummary/master/util/array_reduction.js | 10 // https://raw.github.com/rafaelw/ChangeSummary/master/util/array_reduction.js |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 void _reduce() { | 49 void _reduce() { |
| 50 _scheduled = false; | 50 _scheduled = false; |
| 51 _value = _observers.map((o) => o.value); | 51 _value = _observers.map((o) => o.value); |
| 52 notifyChange(new PropertyChangeRecord(_VALUE)); | 52 notifyChange(new PropertyChangeRecord(_VALUE)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void _scheduleReduce(_) { | 55 void _scheduleReduce(_) { |
| 56 if (_scheduled) return; | 56 if (_scheduled) return; |
| 57 _scheduled = true; | 57 _scheduled = true; |
| 58 runAsync(_reduce); | 58 scheduleMicrotask(_reduce); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void _observeItems(int lengthAdjust) { | 61 void _observeItems(int lengthAdjust) { |
| 62 if (lengthAdjust > 0) { | 62 if (lengthAdjust > 0) { |
| 63 for (int i = 0; i < lengthAdjust; i++) { | 63 for (int i = 0; i < lengthAdjust; i++) { |
| 64 int len = _observers.length; | 64 int len = _observers.length; |
| 65 var pathObs = new PathObserver(list, '$len.$_itemPath'); | 65 var pathObs = new PathObserver(list, '$len.$_itemPath'); |
| 66 _subs.add(pathObs.changes.listen(_scheduleReduce)); | 66 _subs.add(pathObs.changes.listen(_scheduleReduce)); |
| 67 _observers.add(pathObs); | 67 _observers.add(pathObs); |
| 68 } | 68 } |
| 69 } else if (lengthAdjust < 0) { | 69 } else if (lengthAdjust < 0) { |
| 70 for (int i = 0; i < -lengthAdjust; i++) { | 70 for (int i = 0; i < -lengthAdjust; i++) { |
| 71 _subs.removeLast().cancel(); | 71 _subs.removeLast().cancel(); |
| 72 } | 72 } |
| 73 int len = _observers.length; | 73 int len = _observers.length; |
| 74 _observers.removeRange(len + lengthAdjust, len); | 74 _observers.removeRange(len + lengthAdjust, len); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 } | 77 } |
| OLD | NEW |