flutter/examples/fn/lib/style.dart
Rafael Weinstein 202f99d71d Initial commit of Effen reactive framework experiment for Sky
This is just a proof of concept. If we like this direction, it will move out of the examples directory (likely re-written) and be committed in smaller pieces with unit tests and formal reviews.

TBR=abarth
BUG=

Review URL: https://codereview.chromium.org/971183002
2015-03-02 20:55:02 -08:00

37 lines
786 B
Dart

part of fn;
class Style {
final String _className;
static Map<String, Style> _cache = null;
static int nextStyleId = 1;
static String nextClassName(String styles) {
assert(sky.document != null);
var className = "style$nextStyleId";
nextStyleId++;
var styleNode = sky.document.createElement('style');
styleNode.setChild(new sky.Text(".$className { $styles }"));
sky.document.appendChild(styleNode);
return className;
}
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;
}
Style._internal(this._className);
}