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

Side by Side Diff: sky/examples/fn/lib/style.dart

Issue 973613004: Clean up some Dart idioms in fn (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 | « sky/examples/fn/lib/reflect.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
1 part of fn; 5 part of fn;
2 6
3 class Style { 7 class Style {
4 final String _className; 8 final String _className;
5 static Map<String, Style> _cache = null; 9 static final Map<String, Style> _cache = new HashMap<String, Style>();
6 10
7 static int nextStyleId = 1; 11 static int nextStyleId = 1;
8 12
9 static String nextClassName(String styles) { 13 static String nextClassName(String styles) {
10 assert(sky.document != null); 14 assert(sky.document != null);
11 var className = "style$nextStyleId"; 15 String className = "style$nextStyleId";
12 nextStyleId++; 16 nextStyleId++;
13 17
14 var styleNode = sky.document.createElement('style'); 18 sky.Element styleNode = sky.document.createElement('style');
15 styleNode.setChild(new sky.Text(".$className { $styles }")); 19 styleNode.setChild(new sky.Text(".$className { $styles }"));
16 sky.document.appendChild(styleNode); 20 sky.document.appendChild(styleNode);
17 21
18 return className; 22 return className;
19 } 23 }
20 24
21 factory Style(String styles) { 25 factory Style(String styles) {
22 if (_cache == null) { 26 return _cache.putIfAbsent(styles, () {
23 _cache = new HashMap<String, Style>(); 27 return new Style._internal(nextClassName(styles));
24 } 28 });
25
26 var style = _cache[styles];
27 if (style == null) {
28 style = new Style._internal(nextClassName(styles));
29 _cache[styles] = style;
30 }
31
32 return style;
33 } 29 }
34 30
35 Style._internal(this._className); 31 Style._internal(this._className);
36 } 32 }
OLDNEW
« no previous file with comments | « sky/examples/fn/lib/reflect.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698