Commit 3f347184 authored by Adam Barth's avatar Adam Barth

Clean up some Dart idioms in fn

This CL adds license blocks and cleans up a number of Dart idioms in fn.
Specifically, I've marked several fields as |final| and used Map#putIfAbsent in
some appropriate places.

R=rafaelw@chromium.org

Review URL: https://codereview.chromium.org/973613004
parent e5a51a30
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of fn;
List<Component> _dirtyComponents = new List<Component>();
......@@ -30,7 +34,7 @@ abstract class Component extends Node {
bool _dirty = true; // components begin dirty because they haven't rendered.
Node _rendered = null;
bool _removed = false;
int _order;
final int _order;
static int _currentOrder = 0;
bool _stateful;
static Component _currentlyRendering;
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library fn;
import 'dart:async';
......@@ -11,7 +15,7 @@ part 'style.dart';
bool _checkedMode;
bool debugWarnings() {
bool _debugWarnings() {
void testFn(double i) {}
if (_checkedMode == null) {
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of fn;
void parentInsertBefore(sky.ParentNode parent,
sky.Node node,
sky.Node ref) {
void _parentInsertBefore(sky.ParentNode parent,
sky.Node node,
sky.Node ref) {
if (ref != null) {
ref.insertBefore([node]);
} else {
......@@ -41,7 +45,7 @@ class Text extends Node {
bool _sync(Node old, sky.ParentNode host, sky.Node insertBefore) {
if (old == null) {
_root = new sky.Text(data);
parentInsertBefore(host, _root, insertBefore);
_parentInsertBefore(host, _root, insertBefore);
return false;
}
......@@ -51,7 +55,7 @@ class Text extends Node {
}
}
var _emptyList = new List<Node>();
final List<Node> _emptyList = new List<Node>();
abstract class Element extends Node {
......@@ -102,7 +106,7 @@ abstract class Element extends Node {
_className = style == null ? '': style._className;
_children = children == null ? _emptyList : children;
if (debugWarnings()) {
if (_debugWarnings()) {
_debugReportDuplicateIds();
}
}
......@@ -194,7 +198,7 @@ abstract class Element extends Node {
assert(child._root is sky.Node);
}
parentInsertBefore(host, _root, insertBefore);
_parentInsertBefore(host, _root, insertBefore);
return false;
}
......@@ -283,7 +287,7 @@ abstract class Element extends Node {
oldNodeIdMap[currentNode._key] = null; // mark it reordered.
// print("Reparenting ${currentNode._key}");
parentInsertBefore(root, oldNode._root, nextSibling);
_parentInsertBefore(root, oldNode._root, nextSibling);
return true;
}
......@@ -344,7 +348,7 @@ class Container extends Element {
String get _tagName => 'div';
static Container _emptyContainer = new Container();
static final Container _emptyContainer = new Container();
Element get _emptyElement => _emptyContainer;
......@@ -389,7 +393,7 @@ class Image extends Element {
String get _tagName => 'img';
static Image _emptyImage = new Image();
static final Image _emptyImage = new Image();
Element get _emptyElement => _emptyImage;
String src;
......@@ -457,7 +461,7 @@ class Anchor extends Element {
String get _tagName => 'a';
static Anchor _emptyAnchor = new Anchor();
static final Anchor _emptyAnchor = new Anchor();
String href;
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library reflect;
import 'dart:mirrors';
import 'dart:collection';
HashMap<ClassMirror, List> _fieldCache = new HashMap<ClassMirror, List>();
final HashMap<ClassMirror, List> _fieldCache = new HashMap<ClassMirror, List>();
List<Symbol> _getPublicFields(ClassMirror mirror) {
var fields = _fieldCache[mirror];
if (fields == null) {
fields = new List<Symbol>();
_fieldCache[mirror] = fields;
return _fieldCache.putIfAbsent(mirror, () {
List<Symbol> fields = new List<Symbol>();
while (mirror != null) {
var decls = mirror.declarations;
......@@ -25,9 +27,9 @@ List<Symbol> _getPublicFields(ClassMirror mirror) {
mirror = mirror.superclass;
}
}
return fields;
return fields;
});
}
void copyPublicFields(Object source, Object target) {
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of fn;
class Style {
final String _className;
static Map<String, Style> _cache = null;
static final Map<String, Style> _cache = new HashMap<String, Style>();
static int nextStyleId = 1;
static String nextClassName(String styles) {
assert(sky.document != null);
var className = "style$nextStyleId";
String className = "style$nextStyleId";
nextStyleId++;
var styleNode = sky.document.createElement('style');
sky.Element styleNode = sky.document.createElement('style');
styleNode.setChild(new sky.Text(".$className { $styles }"));
sky.document.appendChild(styleNode);
......@@ -19,17 +23,9 @@ class Style {
}
factory Style(String styles) {
if (_cache == null) {
_cache = new HashMap<String, Style>();
}
var style = _cache[styles];
if (style == null) {
style = new Style._internal(nextClassName(styles));
_cache[styles] = style;
}
return style;
return _cache.putIfAbsent(styles, () {
return new Style._internal(nextClassName(styles));
});
}
Style._internal(this._className);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment