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; part of fn;
List<Component> _dirtyComponents = new List<Component>(); List<Component> _dirtyComponents = new List<Component>();
...@@ -30,7 +34,7 @@ abstract class Component extends Node { ...@@ -30,7 +34,7 @@ abstract class Component extends Node {
bool _dirty = true; // components begin dirty because they haven't rendered. bool _dirty = true; // components begin dirty because they haven't rendered.
Node _rendered = null; Node _rendered = null;
bool _removed = false; bool _removed = false;
int _order; final int _order;
static int _currentOrder = 0; static int _currentOrder = 0;
bool _stateful; bool _stateful;
static Component _currentlyRendering; 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; library fn;
import 'dart:async'; import 'dart:async';
...@@ -11,7 +15,7 @@ part 'style.dart'; ...@@ -11,7 +15,7 @@ part 'style.dart';
bool _checkedMode; bool _checkedMode;
bool debugWarnings() { bool _debugWarnings() {
void testFn(double i) {} void testFn(double i) {}
if (_checkedMode == null) { 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; part of fn;
void parentInsertBefore(sky.ParentNode parent, void _parentInsertBefore(sky.ParentNode parent,
sky.Node node, sky.Node node,
sky.Node ref) { sky.Node ref) {
if (ref != null) { if (ref != null) {
...@@ -41,7 +45,7 @@ class Text extends Node { ...@@ -41,7 +45,7 @@ class Text extends Node {
bool _sync(Node old, sky.ParentNode host, sky.Node insertBefore) { bool _sync(Node old, sky.ParentNode host, sky.Node insertBefore) {
if (old == null) { if (old == null) {
_root = new sky.Text(data); _root = new sky.Text(data);
parentInsertBefore(host, _root, insertBefore); _parentInsertBefore(host, _root, insertBefore);
return false; return false;
} }
...@@ -51,7 +55,7 @@ class Text extends Node { ...@@ -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 { abstract class Element extends Node {
...@@ -102,7 +106,7 @@ abstract class Element extends Node { ...@@ -102,7 +106,7 @@ abstract class Element extends Node {
_className = style == null ? '': style._className; _className = style == null ? '': style._className;
_children = children == null ? _emptyList : children; _children = children == null ? _emptyList : children;
if (debugWarnings()) { if (_debugWarnings()) {
_debugReportDuplicateIds(); _debugReportDuplicateIds();
} }
} }
...@@ -194,7 +198,7 @@ abstract class Element extends Node { ...@@ -194,7 +198,7 @@ abstract class Element extends Node {
assert(child._root is sky.Node); assert(child._root is sky.Node);
} }
parentInsertBefore(host, _root, insertBefore); _parentInsertBefore(host, _root, insertBefore);
return false; return false;
} }
...@@ -283,7 +287,7 @@ abstract class Element extends Node { ...@@ -283,7 +287,7 @@ abstract class Element extends Node {
oldNodeIdMap[currentNode._key] = null; // mark it reordered. oldNodeIdMap[currentNode._key] = null; // mark it reordered.
// print("Reparenting ${currentNode._key}"); // print("Reparenting ${currentNode._key}");
parentInsertBefore(root, oldNode._root, nextSibling); _parentInsertBefore(root, oldNode._root, nextSibling);
return true; return true;
} }
...@@ -344,7 +348,7 @@ class Container extends Element { ...@@ -344,7 +348,7 @@ class Container extends Element {
String get _tagName => 'div'; String get _tagName => 'div';
static Container _emptyContainer = new Container(); static final Container _emptyContainer = new Container();
Element get _emptyElement => _emptyContainer; Element get _emptyElement => _emptyContainer;
...@@ -389,7 +393,7 @@ class Image extends Element { ...@@ -389,7 +393,7 @@ class Image extends Element {
String get _tagName => 'img'; String get _tagName => 'img';
static Image _emptyImage = new Image(); static final Image _emptyImage = new Image();
Element get _emptyElement => _emptyImage; Element get _emptyElement => _emptyImage;
String src; String src;
...@@ -457,7 +461,7 @@ class Anchor extends Element { ...@@ -457,7 +461,7 @@ class Anchor extends Element {
String get _tagName => 'a'; String get _tagName => 'a';
static Anchor _emptyAnchor = new Anchor(); static final Anchor _emptyAnchor = new Anchor();
String href; 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; library reflect;
import 'dart:mirrors'; import 'dart:mirrors';
import 'dart:collection'; 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) { List<Symbol> _getPublicFields(ClassMirror mirror) {
var fields = _fieldCache[mirror]; return _fieldCache.putIfAbsent(mirror, () {
if (fields == null) { List<Symbol> fields = new List<Symbol>();
fields = new List<Symbol>();
_fieldCache[mirror] = fields;
while (mirror != null) { while (mirror != null) {
var decls = mirror.declarations; var decls = mirror.declarations;
...@@ -25,9 +27,9 @@ List<Symbol> _getPublicFields(ClassMirror mirror) { ...@@ -25,9 +27,9 @@ List<Symbol> _getPublicFields(ClassMirror mirror) {
mirror = mirror.superclass; mirror = mirror.superclass;
} }
}
return fields; return fields;
});
} }
void copyPublicFields(Object source, Object target) { 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; part of fn;
class Style { class Style {
final String _className; final String _className;
static Map<String, Style> _cache = null; static final Map<String, Style> _cache = new HashMap<String, Style>();
static int nextStyleId = 1; static int nextStyleId = 1;
static String nextClassName(String styles) { static String nextClassName(String styles) {
assert(sky.document != null); assert(sky.document != null);
var className = "style$nextStyleId"; String className = "style$nextStyleId";
nextStyleId++; nextStyleId++;
var styleNode = sky.document.createElement('style'); sky.Element styleNode = sky.document.createElement('style');
styleNode.setChild(new sky.Text(".$className { $styles }")); styleNode.setChild(new sky.Text(".$className { $styles }"));
sky.document.appendChild(styleNode); sky.document.appendChild(styleNode);
...@@ -19,17 +23,9 @@ class Style { ...@@ -19,17 +23,9 @@ class Style {
} }
factory Style(String styles) { factory Style(String styles) {
if (_cache == null) { return _cache.putIfAbsent(styles, () {
_cache = new HashMap<String, Style>(); return new Style._internal(nextClassName(styles));
} });
var style = _cache[styles];
if (style == null) {
style = new Style._internal(nextClassName(styles));
_cache[styles] = style;
}
return style;
} }
Style._internal(this._className); 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