chore: dartfmt Dart code in the repo

This commit is contained in:
Kevin Moore
2015-05-08 19:51:19 -07:00
parent a5638a940c
commit 7844e3a275
27 changed files with 252 additions and 332 deletions

View File

@ -7,7 +7,6 @@ import 'dart:html';
import 'package:angular2/src/test_lib/benchmark_util.dart';
main() {
var count = getIntParameter('elements');
var m = new Module()
@ -36,13 +35,12 @@ main() {
bindAction('#compileWithBindings', compileWithBindings);
bindAction('#compileNoBindings', compileNoBindings);
}
loadTemplate(templateId, repeatCount) {
String result = '';
var content = document.querySelector("#${templateId}").innerHtml;
for (var i=0; i<repeatCount; i++) {
for (var i = 0; i < repeatCount; i++) {
result += content;
}
return createTemplate(result.replaceAll(new RegExp(r'[\[\]]'), ''));
@ -54,68 +52,39 @@ class IdentitySanitizer implements NodeTreeSanitizer {
createTemplate(String html) {
var div = document.createElement('div');
div.setInnerHtml(html, treeSanitizer:new IdentitySanitizer());
div.setInnerHtml(html, treeSanitizer: new IdentitySanitizer());
return div;
}
@Directive(
selector: '[dir0]',
map: const {
'attr0': '=>prop'
}
)
@Directive(selector: '[dir0]', map: const {'attr0': '=>prop'})
class Dir0 {
Object prop;
}
@Directive(
selector: '[dir1]',
map: const {
'attr1': '=>prop'
}
)
@Directive(selector: '[dir1]', map: const {'attr1': '=>prop'})
class Dir1 {
Object prop;
constructor(Dir0 dir0) {
}
constructor(Dir0 dir0) {}
}
@Directive(
selector: '[dir2]',
map: const {
'attr2': '=>prop'
}
)
@Directive(selector: '[dir2]', map: const {'attr2': '=>prop'})
class Dir2 {
Object prop;
constructor(Dir1 dir1) {
}
constructor(Dir1 dir1) {}
}
@Directive(
selector: '[dir3]',
map: const {
'attr3': '=>prop'
}
)
@Directive(selector: '[dir3]', map: const {'attr3': '=>prop'})
class Dir3 {
Object prop;
constructor(Dir2 dir2) {
}
constructor(Dir2 dir2) {}
}
@Directive(
selector: '[dir4]',
map: const {
'attr4': '=>prop'
}
)
@Directive(selector: '[dir4]', map: const {'attr4': '=>prop'})
class Dir4 {
Object prop;
constructor(Dir3 dir3) {
}
}
constructor(Dir3 dir3) {}
}

View File

@ -5,9 +5,7 @@ import 'dart:html';
import 'package:angular/angular.dart';
import 'package:angular2/src/test_lib/benchmark_util.dart';
@Component(
selector: 'scroll-app',
template: '''
@Component(selector: 'scroll-app', template: '''
<div>
<div style="display: flex">
<scroll-area scroll-top="scrollTop"></scroll-area>
@ -29,7 +27,7 @@ class App implements ShadowRootAware {
int appSize = getIntParameter('appSize');
iterationCount = getIntParameter('iterationCount');
scrollIncrement = getIntParameter('scrollIncrement');
appSize = appSize > 1 ? appSize - 1 : 0; // draw at least one table
appSize = appSize > 1 ? appSize - 1 : 0; // draw at least one table
scrollAreas = new List.generate(appSize, (i) => i);
}

View File

@ -3,43 +3,25 @@ library cells;
import 'package:angular/angular.dart';
import 'common.dart';
@Component(
selector: 'company-name',
template: '''
@Component(selector: 'company-name', template: '''
<div style="width: {{width}}">{{company.name}}</div>
''',
map: const {
'company': '=>company',
'cell-width': '=>width',
})
''', map: const {'company': '=>company', 'cell-width': '=>width',})
class CompanyNameComponent {
String width;
Company company;
}
@Component(
selector: 'opportunity-name',
template: '''
@Component(selector: 'opportunity-name', template: '''
<div style="width: {{width}}">{{opportunity.name}}</div>
''',
map: const {
'opportunity': '=>opportunity',
'cell-width': '=>width',
})
''', map: const {'opportunity': '=>opportunity', 'cell-width': '=>width',})
class OpportunityNameComponent {
String width;
Opportunity opportunity;
}
@Component(
selector: 'offering-name',
template: '''
@Component(selector: 'offering-name', template: '''
<div style="width: {{width}}">{{offering.name}}</div>
''',
map: const {
'offering': '=>offering',
'cell-width': '=>width',
})
''', map: const {'offering': '=>offering', 'cell-width': '=>width',})
class OfferingNameComponent {
String width;
Offering offering;
@ -52,15 +34,11 @@ class Stage {
Function apply;
String get styleString => style != null
? style.keys
.map((prop) => '$prop: ${style[prop]}')
.join(';')
: '';
? style.keys.map((prop) => '$prop: ${style[prop]}').join(';')
: '';
}
@Component(
selector: 'stage-buttons',
template: '''
@Component(selector: 'stage-buttons', template: '''
<div style="width: {{width}}">
<button ng-repeat="stage in stages"
ng-disabled="stage.isDisabled"
@ -69,11 +47,7 @@ class Stage {
{{stage.name}}
</button>
</div>
''',
map: const {
'offering': '=>offering',
'cell-width': '=>width',
})
''', map: const {'offering': '=>offering', 'cell-width': '=>width',})
class StageButtonsComponent {
Offering _offering;
List<Stage> stages;
@ -92,42 +66,30 @@ class StageButtonsComponent {
_computeStageButtons() {
bool disabled = true;
stages = STATUS_LIST
.map((String status) {
stages = STATUS_LIST.map((String status) {
bool isCurrent = offering.status == status;
var stage = new Stage();
stage
..name = status
..isDisabled = disabled
..style = {
'background-color': disabled
? '#DDD'
: isCurrent
? '#DDF'
: '#FDD'
};
'background-color': disabled ? '#DDD' : isCurrent ? '#DDF' : '#FDD'
};
if (isCurrent) {
disabled = false;
}
return stage;
})
.toList();
}).toList();
}
}
@Component(
selector: 'account-cell',
template: '''
@Component(selector: 'account-cell', template: '''
<div style="width: {{width}}">
<a href="/account/{{account.accountId}}">
{{account.accountId}}
</a>
</div>
''',
map: const {
'account': '=>account',
'cell-width': '=>width',
})
''', map: const {'account': '=>account', 'cell-width': '=>width',})
class AccountCellComponent {
Account account;
String width;
@ -136,10 +98,7 @@ class AccountCellComponent {
@Component(
selector: 'formatted-cell',
template: '''<div style="width: {{width}}">{{formattedValue}}</div>''',
map: const {
'value': '=>value',
'cell-width': '=>width',
})
map: const {'value': '=>value', 'cell-width': '=>width',})
class FormattedCellComponent {
String formattedValue;
String width;

View File

@ -23,32 +23,25 @@ const DUE_DATE_WIDTH = 100;
const END_DATE_WIDTH = 100;
const AAT_STATUS_WIDTH = 100;
const ROW_WIDTH = COMPANY_NAME_WIDTH +
OPPORTUNITY_NAME_WIDTH +
OFFERING_NAME_WIDTH +
ACCOUNT_CELL_WIDTH +
BASE_POINTS_WIDTH +
KICKER_POINTS_WIDTH +
STAGE_BUTTONS_WIDTH +
BUNDLES_WIDTH +
DUE_DATE_WIDTH +
END_DATE_WIDTH +
AAT_STATUS_WIDTH;
OPPORTUNITY_NAME_WIDTH +
OFFERING_NAME_WIDTH +
ACCOUNT_CELL_WIDTH +
BASE_POINTS_WIDTH +
KICKER_POINTS_WIDTH +
STAGE_BUTTONS_WIDTH +
BUNDLES_WIDTH +
DUE_DATE_WIDTH +
END_DATE_WIDTH +
AAT_STATUS_WIDTH;
const STATUS_LIST = const [
'Planned', 'Pitched', 'Won', 'Lost'
];
const STATUS_LIST = const ['Planned', 'Pitched', 'Won', 'Lost'];
const AAT_STATUS_LIST = const [
'Active', 'Passive', 'Abandoned'
];
const AAT_STATUS_LIST = const ['Active', 'Passive', 'Abandoned'];
// Imitate Streamy entities.
class RawEntity
extends Object
with MapMixin<String, dynamic>
implements ObservableMap<String, dynamic> {
class RawEntity extends Object with MapMixin<String, dynamic>
implements ObservableMap<String, dynamic> {
ObservableMap _data = new ObservableMap();
@override
@ -60,7 +53,7 @@ implements ObservableMap<String, dynamic> {
}
@override
operator[](String key) {
operator [](String key) {
if (!key.contains('.')) {
return _data[key];
}
@ -74,7 +67,7 @@ implements ObservableMap<String, dynamic> {
}
@override
operator[]=(String key, value) {
operator []=(String key, value) {
if (!key.contains('.')) {
_data[key] = value;
return;
@ -115,7 +108,7 @@ implements ObservableMap<String, dynamic> {
bool deliverChanges() => _data.deliverChanges();
@override
notifyPropertyChange(Symbol field, Object oldValue, Object newValue) =>
_data.notifyPropertyChange(field, oldValue, newValue);
_data.notifyPropertyChange(field, oldValue, newValue);
@override
void notifyChange(ChangeRecord record) {
_data.notifyChange(record);
@ -199,7 +192,6 @@ class Opportunity extends RawEntity {
set name(String val) {
this['name'] = val;
}
}
class Account extends RawEntity {

View File

@ -9,7 +9,8 @@ import 'cells.dart';
class MyAppModule extends Module {
MyAppModule() {
bind(ResourceResolverConfig, toValue: new ResourceResolverConfig.resolveRelativeUrls(false));
bind(ResourceResolverConfig,
toValue: new ResourceResolverConfig.resolveRelativeUrls(false));
bind(App);
bind(ScrollAreaComponent);
bind(ScrollItemComponent);
@ -23,7 +24,5 @@ class MyAppModule extends Module {
}
void main() {
applicationFactory()
.addModule(new MyAppModule())
.run();
applicationFactory().addModule(new MyAppModule()).run();
}

View File

@ -3,7 +3,7 @@ library random_data;
import 'common.dart';
List<Offering> generateOfferings(int count) =>
new List.generate(count, generateOffering);
new List.generate(count, generateOffering);
Offering generateOffering(int seed) {
final res = new Offering();
@ -22,24 +22,32 @@ Offering generateOffering(int seed) {
}
Company generateCompany(int seed) {
return new Company()
..name = generateName(seed);
return new Company()..name = generateName(seed);
}
Opportunity generateOpportunity(int seed) {
return new Opportunity()
..name = generateName(seed);
return new Opportunity()..name = generateName(seed);
}
Account generateAccount(int seed) {
return new Account()
..accountId = seed;
return new Account()..accountId = seed;
}
String generateName(int seed) {
const names = const [
'Foo', 'Bar', 'Baz', 'Qux', 'Quux', 'Garply', 'Waldo', 'Fred', 'Plugh',
'Xyzzy', 'Thud', 'Cruft', 'Stuff'
'Foo',
'Bar',
'Baz',
'Qux',
'Quux',
'Garply',
'Waldo',
'Fred',
'Plugh',
'Xyzzy',
'Thud',
'Cruft',
'Stuff'
];
return names[seed % names.length];
}
@ -49,13 +57,17 @@ DateTime randomDate(int seed, {DateTime minDate}) {
minDate = new DateTime.now();
}
const offsets = const[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const offsets = const [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
return minDate.add(new Duration(days: offsets[seed % offsets.length]));
}
String randomString(int seed) {
return new String.fromCharCodes(new List.generate(
const[5, 7, 9, 11, 13][seed % 5],
(i) => 'a'.codeUnitAt(0) + const[0, 1, 2, 3, 4, 5, 6, 7, 8][seed % 9] + i
));
return new String.fromCharCodes(new List.generate(const [
5,
7,
9,
11,
13
][seed % 5], (i) =>
'a'.codeUnitAt(0) + const [0, 1, 2, 3, 4, 5, 6, 7, 8][seed % 9] + i));
}

View File

@ -9,9 +9,7 @@ import 'random_data.dart';
@Component(
selector: 'scroll-area',
templateUrl: 'scroll_area.html',
map: const {
'scroll-top': '=>scrollTop',
})
map: const {'scroll-top': '=>scrollTop',})
class ScrollAreaComponent implements ShadowRootAware {
Element scrollDiv;
List<Offering> _fullList;
@ -32,10 +30,10 @@ class ScrollAreaComponent implements ShadowRootAware {
scrollDiv = shadowRoot.querySelector('#scrollDiv');
onScroll();
scrollDivStyle.addAll({
'height': '${VIEW_PORT_HEIGHT}px',
'width': '1000px',
'border': '1px solid #000',
'overflow': 'scroll',
'height': '${VIEW_PORT_HEIGHT}px',
'width': '1000px',
'border': '1px solid #000',
'overflow': 'scroll',
});
innerStyle['width'] = '${ROW_WIDTH}px';
}
@ -52,7 +50,8 @@ class ScrollAreaComponent implements ShadowRootAware {
int padding = iStart * ITEM_HEIGHT;
innerStyle['height'] = '${HEIGHT - padding}px';
paddingStyle['height'] = '${padding}px';
visibleItems..clear()..addAll(_fullList.getRange(iStart, iEnd));
visibleItems
..clear()
..addAll(_fullList.getRange(iStart, iEnd));
}
}

View File

@ -6,36 +6,33 @@ import 'common.dart';
@Component(
selector: 'scroll-item',
templateUrl: 'scroll_item.html',
map: const {
'offering': '=>offering',
})
map: const {'offering': '=>offering',})
class ScrollItemComponent implements ShadowRootAware {
Offering offering;
Offering offering;
// Init empty maps and populate later. There seems to be a bug in Angular
// that makes it choke on pre-populated style maps.
Map itemStyle = {};
// Init empty maps and populate later. There seems to be a bug in Angular
// that makes it choke on pre-populated style maps.
Map itemStyle = {};
@override
void onShadowRoot(_) {
itemStyle.addAll({
'height': '${ITEM_HEIGHT}px',
'line-height': '${ITEM_HEIGHT}px',
'font-size': '18px',
'display': 'flex',
'justify-content': 'space-between',
});
}
get companyNameWidth => '${COMPANY_NAME_WIDTH}px';
get opportunityNameWidth => '${OPPORTUNITY_NAME_WIDTH}px';
get offeringNameWidth => '${OFFERING_NAME_WIDTH}px';
get accountCellWidth => '${ACCOUNT_CELL_WIDTH}px';
get basePointsWidth => '${BASE_POINTS_WIDTH}px';
get kickerPointsWidth => '${KICKER_POINTS_WIDTH}px';
get stageButtonsWidth => '${STAGE_BUTTONS_WIDTH}px';
get bundlesWidth => '${BUNDLES_WIDTH}px';
get dueDateWidth => '${DUE_DATE_WIDTH}px';
get endDateWidth => '${END_DATE_WIDTH}px';
get aatStatusWidth => '${AAT_STATUS_WIDTH}px';
@override
void onShadowRoot(_) {
itemStyle.addAll({
'height': '${ITEM_HEIGHT}px',
'line-height': '${ITEM_HEIGHT}px',
'font-size': '18px',
'display': 'flex',
'justify-content': 'space-between',
});
}
get companyNameWidth => '${COMPANY_NAME_WIDTH}px';
get opportunityNameWidth => '${OPPORTUNITY_NAME_WIDTH}px';
get offeringNameWidth => '${OFFERING_NAME_WIDTH}px';
get accountCellWidth => '${ACCOUNT_CELL_WIDTH}px';
get basePointsWidth => '${BASE_POINTS_WIDTH}px';
get kickerPointsWidth => '${KICKER_POINTS_WIDTH}px';
get stageButtonsWidth => '${STAGE_BUTTONS_WIDTH}px';
get bundlesWidth => '${BUNDLES_WIDTH}px';
get dueDateWidth => '${DUE_DATE_WIDTH}px';
get endDateWidth => '${END_DATE_WIDTH}px';
get aatStatusWidth => '${AAT_STATUS_WIDTH}px';
}

View File

@ -6,10 +6,11 @@ import 'package:angular/application_factory.dart';
import 'package:angular2/src/test_lib/benchmark_util.dart';
setup() {
var m = new Module()
..bind(CompilerConfig, toValue: new CompilerConfig.withOptions(elementProbeEnabled: false))
..bind(ScopeDigestTTL, toFactory: () => new ScopeDigestTTL.value(15), inject: [])
..bind(CompilerConfig,
toValue: new CompilerConfig.withOptions(elementProbeEnabled: false))
..bind(ScopeDigestTTL,
toFactory: () => new ScopeDigestTTL.value(15), inject: [])
..bind(TreeComponent);
final injector = applicationFactory().addModule(m).run();
@ -33,9 +34,9 @@ main() {
createDom() {
zone.run(() {
var values = count++ % 2 == 0 ?
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*'] :
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', '-'];
var values = count++ % 2 == 0
? ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*']
: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', '-'];
rootScope.context['initData'] = buildTree(maxDepth, values, 0);
});
@ -46,23 +47,21 @@ main() {
}
@Component(
selector: 'tree',
map: const {'data': '=>data'},
template: '<span> {{data.value}}'
'<span ng-if="data.right != null"><tree data=data.right></span>'
'<span ng-if="data.left != null"><tree data=data.left></span>'
'</span>'
)
selector: 'tree',
map: const {'data': '=>data'},
template: '<span> {{data.value}}'
'<span ng-if="data.right != null"><tree data=data.right></span>'
'<span ng-if="data.left != null"><tree data=data.left></span>'
'</span>')
class TreeComponent {
var data;
}
buildTree(maxDepth, values, curDepth) {
if (maxDepth == curDepth) return new TreeNode('');
return new TreeNode(
values[curDepth],
buildTree(maxDepth, values, curDepth+1),
buildTree(maxDepth, values, curDepth+1));
return new TreeNode(values[curDepth],
buildTree(maxDepth, values, curDepth + 1),
buildTree(maxDepth, values, curDepth + 1));
}
class TreeNode {
@ -71,4 +70,3 @@ class TreeNode {
TreeNode right;
TreeNode([this.value, this.left, this.right]);
}