Remove one more use of mirrors: Components now have to explicitly sync their fields.
This also removes one bit of magic to make it more obvious what on is going on during a sync, which should hopefully help. Components have to decide if they support being stateful or not. If they do, then they must implement syncFields() and have mutable fields; if they don't, then they must have final fields. This isn't particularly enforced, though. This also renames _willSync() to _retainStatefulNodeIfPossible(), for clarity, and fixes some minor style issues and one typo that was breaking the drawer. R=abarth@chromium.org Review URL: https://codereview.chromium.org/1174023003
This commit is contained in:
@@ -46,6 +46,8 @@ class StocksApp extends App {
|
||||
_drawerController = new DrawerController(_handleDrawerStatusChanged);
|
||||
}
|
||||
|
||||
void syncFields(StocksApp source) { }
|
||||
|
||||
bool _isSearching = false;
|
||||
String _searchQuery;
|
||||
|
||||
|
||||
@@ -12,10 +12,11 @@ import 'dart:math' as math;
|
||||
import 'dart:sky' as sky;
|
||||
|
||||
class StockArrow extends Component {
|
||||
double percentChange;
|
||||
|
||||
StockArrow({ Object key, this.percentChange }) : super(key: key);
|
||||
|
||||
final double percentChange;
|
||||
|
||||
int _colorIndexForPercentChange(double percentChange) {
|
||||
double maxPercent = 10.0;
|
||||
double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) / maxPercent;
|
||||
@@ -71,4 +72,5 @@ class StockArrow extends Component {
|
||||
height: size,
|
||||
margin: const EdgeDims.symmetric(horizontal: 5.0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import 'stock_data.dart';
|
||||
import 'stock_row.dart';
|
||||
|
||||
class Stocklist extends FixedHeightScrollable {
|
||||
String query;
|
||||
List<Stock> stocks;
|
||||
|
||||
Stocklist({
|
||||
Object key,
|
||||
@@ -17,6 +15,15 @@ class Stocklist extends FixedHeightScrollable {
|
||||
this.query
|
||||
}) : super(itemHeight: StockRow.kHeight, key: key);
|
||||
|
||||
String query;
|
||||
List<Stock> stocks;
|
||||
|
||||
void syncFields(Stocklist source) {
|
||||
query = source.query;
|
||||
stocks = source.stocks;
|
||||
super.syncFields(source);
|
||||
}
|
||||
|
||||
List<UINode> buildItems(int start, int count) {
|
||||
var filteredStocks = stocks.where((stock) {
|
||||
return query == null ||
|
||||
|
||||
@@ -8,10 +8,15 @@ import 'package:sky/framework/components2/checkbox.dart';
|
||||
import 'package:sky/framework/theme/view_configuration.dart';
|
||||
|
||||
class StockMenu extends Component {
|
||||
PopupMenuController controller;
|
||||
|
||||
StockMenu({Object key, this.controller, this.autorefresh: false, this.onAutorefreshChanged}) : super(key: key);
|
||||
StockMenu({
|
||||
Object key,
|
||||
this.controller,
|
||||
this.autorefresh: false,
|
||||
this.onAutorefreshChanged
|
||||
}) : super(key: key);
|
||||
|
||||
final PopupMenuController controller;
|
||||
final bool autorefresh;
|
||||
final ValueChanged onAutorefreshChanged;
|
||||
|
||||
|
||||
@@ -12,14 +12,13 @@ import 'stock_arrow.dart';
|
||||
import 'stock_data.dart';
|
||||
|
||||
class StockRow extends Component {
|
||||
|
||||
StockRow({ Stock stock }) : this.stock = stock, super(key: stock.symbol);
|
||||
|
||||
final Stock stock;
|
||||
|
||||
static const double kHeight = 70.0;
|
||||
|
||||
Stock stock;
|
||||
|
||||
StockRow({ Stock stock }) : super(key: stock.symbol) {
|
||||
this.stock = stock;
|
||||
}
|
||||
|
||||
UINode build() {
|
||||
String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user