Skip to content

Commit 15fb40e

Browse files
committed
fix(): Fixes ALL dartanalyzer problems (so far).
1 parent 2cc9ae5 commit 15fb40e

File tree

12 files changed

+530
-50
lines changed

12 files changed

+530
-50
lines changed

src/components/button/button.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
import {
2+
inject,
3+
injectAsync,
4+
ComponentFixture,
5+
TestComponentBuilder,
6+
beforeEachProviders,
7+
} from 'angular2/testing';
18
import {
29
it,
310
iit,
411
describe,
512
ddescribe,
613
expect,
7-
inject,
8-
injectAsync,
9-
TestComponentBuilder,
10-
beforeEachProviders,
1114
beforeEach,
12-
} from 'angular2/testing';
15+
} from '../../core/facade/testing';
1316
import {provide, Component, DebugElement} from 'angular2/core';
1417
import {By} from 'angular2/platform/browser';
1518

src/components/button/button.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import {Component, ViewEncapsulation, Input, HostBinding, HostListener, ChangeDetectionStrategy} from 'angular2/core';
1+
import {
2+
Component,
3+
ViewEncapsulation,
4+
Input,
5+
HostBinding,
6+
HostListener,
7+
ChangeDetectionStrategy,
8+
} from 'angular2/core';
9+
import {TimerWrapper} from 'angular2/src/facade/async';
210

311
// TODO(jelbourn): Ink ripples.
412
// TODO(jelbourn): Make the `isMouseDown` stuff done with one global listener.
@@ -37,7 +45,7 @@ export class MdButton {
3745
// button continues to look :active after clicking.
3846
// @see http://marcysutton.com/button-focus-hell/
3947
this.isMouseDown = true;
40-
setTimeout(() => { this.isMouseDown = false; }, 100);
48+
TimerWrapper.setTimeout(() => { this.isMouseDown = false; }, 100);
4149
}
4250

4351
setKeyboardFocus($event: any) {

src/components/sidenav/sidenav.spec.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1+
import {
2+
inject,
3+
injectAsync,
4+
ComponentFixture,
5+
TestComponentBuilder,
6+
beforeEachProviders,
7+
} from 'angular2/testing';
18
import {
29
it,
310
iit,
411
describe,
512
ddescribe,
613
expect,
7-
inject,
8-
injectAsync,
9-
TestComponentBuilder,
10-
beforeEachProviders,
1114
beforeEach,
12-
} from 'angular2/testing';
15+
} from '../../core/facade/testing';
16+
import {
17+
getComputedStyle
18+
} from '../../core/facade/html';
1319
import {provide, Component, DebugElement} from 'angular2/core';
1420
import {By} from 'angular2/platform/browser';
15-
16-
import {MdSidenav, MdSidenavLayout, MD_SIDENAV_DIRECTIVES} from './sidenav';
17-
import {AsyncTestFn, FunctionWithParamTokens} from 'angular2/testing';
18-
import {ComponentFixture} from 'angular2/testing';
19-
import {EventEmitter} from 'angular2/core';
2021
import {Predicate} from 'angular2/src/facade/collection';
2122
import {PromiseWrapper} from 'angular2/src/facade/promise';
2223
import {TimerWrapper} from 'angular2/src/facade/async';
24+
import {MdSidenav, MdSidenavLayout, MD_SIDENAV_DIRECTIVES} from './sidenav';
2325

2426

2527
function wait(msec: number) {
2628
let completer = PromiseWrapper.completer();
27-
TimerWrapper.setTimeout(completer.resolve, msec);
29+
TimerWrapper.setTimeout(() => {
30+
completer.resolve(null);
31+
}, msec);
2832
return completer.promise;
2933
}
3034

@@ -38,7 +42,7 @@ function waitOnEvent(fixture: ComponentFixture,
3842
let completer = PromiseWrapper.completer();
3943
let component: any = fixture.debugElement.query(by).componentInstance;
4044
component[propertyName].subscribe(() => {
41-
completer.resolve();
45+
completer.resolve(null);
4246
});
4347
return completer.promise;
4448
}
@@ -63,7 +67,7 @@ export function main() {
6367
testComponent = fixture.debugElement.componentInstance;
6468
fixture.detectChanges();
6569
return wait(1);
66-
}).then((f) => {
70+
}).then((_: any) => {
6771
let openButtonElement = fixture.debugElement.query(By.css('.open'));
6872
openButtonElement.nativeElement.click();
6973
fixture.detectChanges();
@@ -81,8 +85,8 @@ export function main() {
8185

8286
let sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
8387
let sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
84-
expect(window.getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('visible');
85-
expect(window.getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('visible');
88+
expect(getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('visible');
89+
expect(getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('visible');
8690

8791
// Close it.
8892
let closeButtonElement = fixture.debugElement.query(By.css('.close'));
@@ -107,10 +111,10 @@ export function main() {
107111

108112
let sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
109113
let sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
110-
expect(window.getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('hidden');
111-
expect(window.getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('hidden');
114+
expect(getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('hidden');
115+
expect(getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('hidden');
112116
})
113-
.then(done, done.fail);
117+
.then((_: any) => { done(); });
114118
}, 8000);
115119

116120
it('open() and close() return a promise that resolves after the animation ended',
@@ -149,7 +153,7 @@ export function main() {
149153
})
150154
.then((_: any) => promise)
151155
.then((_: any) => expect(called).toBe(true))
152-
.then(done, done.fail);
156+
.then((_: any) => { done(); });
153157
}, 8000);
154158

155159
it('open() twice returns the same promise', (done: any) => {
@@ -175,15 +179,14 @@ export function main() {
175179
promise = sidenav.close();
176180
expect(sidenav.close()).toBe(promise);
177181
})
178-
.then(done, done.fail);
182+
.then((_: any) => { done(); });
179183
});
180184

181185
it('open() then close() cancel animations when called too fast',
182186
(done: any) => {
183187
let fixture: ComponentFixture;
184188
let sidenav: MdSidenav;
185189

186-
let openPromise: Promise<void>;
187190
let closePromise: Promise<void>;
188191
let openCalled: boolean = false;
189192
let openCancelled: boolean = false;
@@ -194,7 +197,7 @@ export function main() {
194197
fixture = f;
195198
sidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
196199

197-
openPromise = sidenav.open().then((_: any) => {
200+
sidenav.open().then((_: any) => {
198201
openCalled = true;
199202
},
200203
() => {
@@ -208,7 +211,7 @@ export function main() {
208211
.then((_: any) => {
209212
closePromise = sidenav.close().then((_: any) => {
210213
closeCalled = true;
211-
}, done.fail);
214+
});
212215
return wait(1);
213216
})
214217
.then((_: any) => {
@@ -220,17 +223,15 @@ export function main() {
220223
expect(openCancelled).toBe(true);
221224
expect(closeCalled).toBe(true);
222225
})
223-
.then(done, done.fail);
226+
.then((_: any) => { done(); });
224227
}, 8000);
225228

226229
it('close() then open() cancel animations when called too fast',
227230
(done: any) => {
228-
let testComponent: BasicTestApp;
229231
let fixture: ComponentFixture;
230232
let sidenav: MdSidenav;
231233

232234
let openPromise: Promise<void>;
233-
let closePromise: Promise<void>;
234235
let closeCalled: boolean = false;
235236
let closeCancelled: boolean = false;
236237
let openCalled: boolean = false;
@@ -250,10 +251,9 @@ export function main() {
250251
})
251252
.then((_: any) => {
252253
// Then close and check behavior.
253-
closePromise = sidenav.close().then((_: any) => {
254+
sidenav.close().then((_: any) => {
254255
closeCalled = true;
255-
},
256-
() => {
256+
}, () => {
257257
closeCancelled = true;
258258
});
259259
})
@@ -276,7 +276,7 @@ export function main() {
276276
expect(closeCancelled).toBe(true);
277277
expect(openCalled).toBe(true);
278278
})
279-
.then(done, done.fail);
279+
.then((_: any) => { done(); });
280280
}, 8000);
281281
});
282282
});

src/components/sidenav/sidenav.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Component,
44
ContentChildren,
55
ElementRef,
6-
EventEmitter,
76
Host,
87
HostBinding,
98
HostListener,
@@ -14,7 +13,8 @@ import {
1413
Type,
1514
ChangeDetectionStrategy
1615
} from 'angular2/core';
17-
import {PromiseWrapper} from 'angular2/src/facade/promise';
16+
import {PromiseWrapper, ObservableWrapper, EventEmitter} from 'angular2/src/facade/async';
17+
import {iterateListLike} from 'angular2/src/facade/collection';
1818
import {BaseException} from 'angular2/src/facade/exceptions';
1919
import {CONST_EXPR, isPresent} from 'angular2/src/facade/lang';
2020
import {Dir} from '../../directives/dir/dir';
@@ -128,9 +128,6 @@ export class MdSidenav {
128128
this.onCloseStart.emit(null);
129129
}
130130

131-
let emitter = isOpen ? this.onOpen : this.onClose;
132-
let other = isOpen ? this.onClose : this.onOpen;
133-
134131
if (isOpen) {
135132
if (this.openPromise_ == null) {
136133
let completer = PromiseWrapper.completer();
@@ -259,13 +256,13 @@ export class MdSidenavLayout implements AfterContentInit {
259256
// If a `Dir` directive exists up the tree, listen direction changes and update the left/right
260257
// properties to point to the proper start/end.
261258
if (dir_ != null) {
262-
dir_.dirChange.subscribe(() => this.validateDrawers_());
259+
dir_.dirChange.add(() => this.validateDrawers_());
263260
}
264261
}
265262

266263
ngAfterContentInit() {
267264
// On changes, assert on consistency.
268-
this.sidenavs_.changes.subscribe(() => this.validateDrawers_());
265+
ObservableWrapper.subscribe(this.sidenavs_.changes, () => this.validateDrawers_());
269266
this.validateDrawers_();
270267
}
271268

@@ -294,17 +291,17 @@ export class MdSidenavLayout implements AfterContentInit {
294291
}
295292

296293
// Ensure that we have at most one start and one end sidenav.
297-
this.sidenavs_.toArray().forEach(drawer => {
298-
if (drawer.align == 'end') {
294+
iterateListLike(this.sidenavs_, (sidenav: any) => {
295+
if (sidenav.align == 'end') {
299296
if (this.end_ != null) {
300297
throw new MdDuplicatedSidenavException('end');
301298
}
302-
this.end_ = drawer;
299+
this.end_ = sidenav;
303300
} else {
304301
if (this.start_ != null) {
305302
throw new MdDuplicatedSidenavException('start');
306303
}
307-
this.start_ = drawer;
304+
this.start_ = sidenav;
308305
}
309306
});
310307

src/core/annotations/one-of.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
* TODO(hansl): Implement this properly in Dart.
44
*/
55
class OneOf {
6-
const OneOf(List<string> values);
6+
const OneOf(List<String> values);
77
}

src/core/facade/html.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "dart:html";
2+
3+
CssStyleDeclaration getComputedStyle(element, [String pseudoElement]) {
4+
return element.getComputedStyle(pseudoElement);
5+
}

src/core/facade/html.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export function getComputedStyle(element: HTMLElement, pseudoElt?: string) {
3+
return window.getComputedStyle(element, pseudoElt);
4+
}

0 commit comments

Comments
 (0)