Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix: lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored and IgorMinar committed Oct 4, 2016
1 parent 2cad6b3 commit ed87c26
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 97 deletions.
4 changes: 2 additions & 2 deletions lib/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ for (var i = 0; i < blockingMethods.length; i++) {
var name = blockingMethods[i];
patchMethod(_global, name, (delegate, symbol, name) => {
return function (s:any, args: any[]) {
return Zone.current.run(delegate, _global, args, name)
}
return Zone.current.run(delegate, _global, args, name);
};
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export function makeZoneAwareAddListener(addFnName: string, removeFnName: string
return target[addFnSymbol](eventName, eventTask.invoke, useCapturing);
}
}

const zone: Zone = Zone.current;
const source = target.constructor['name'] + '.' + addFnName + ':' + eventName;
const data: ListenerTaskMeta = {
Expand Down Expand Up @@ -253,7 +253,7 @@ export function makeZoneAwareListeners(fnName: string) {
return target[EVENT_TASKS]
.filter(task => task.data.eventName === eventName)
.map(task => task.data.handler);
}
};
}

const zoneAwareAddEventListener = makeZoneAwareAddListener(ADD_EVENT_LISTENER, REMOVE_EVENT_LISTENER);
Expand Down
8 changes: 4 additions & 4 deletions lib/jasmine/jasmine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@
let originalJasmineFn: Function = jasmineEnv[methodName];
jasmineEnv[methodName] = function(description: string, specDefinitions: Function) {
return originalJasmineFn.call(this, description, wrapDescribeInZone(specDefinitions));
}
};
});
['it', 'xit', 'fit'].forEach((methodName) => {
let originalJasmineFn: Function = jasmineEnv[methodName];
jasmineEnv[methodName] = function(description: string, specDefinitions: Function, timeout: number) {
arguments[1] = wrapTestInZone(specDefinitions);
return originalJasmineFn.apply(this, arguments);
}
};
});
['beforeEach', 'afterEach'].forEach((methodName) => {
let originalJasmineFn: Function = jasmineEnv[methodName];
jasmineEnv[methodName] = function(specDefinitions: Function, timeout: number) {
arguments[0] = wrapTestInZone(specDefinitions);
return originalJasmineFn.apply(this, arguments);
}
};
});

/**
Expand All @@ -64,7 +64,7 @@
function wrapDescribeInZone(describeBody: Function): Function {
return function() {
return syncZone.run(describeBody, this, arguments as any as any[]);
}
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ if (httpClient && httpClient.ClientRequest) {
let zone = Zone.current;
return new ClientRequest(options, zone.wrap(callback, 'http.ClientRequest'));
}
}
};
}
64 changes: 32 additions & 32 deletions lib/zone-spec/fake-async-test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
(function(global: any) {
interface ScheduledFunction {
endTime: number;
id: number,
id: number;
func: Function;
args: any[];
delay: number;
}

class Scheduler {
// Next scheduler id.
public nextId: number = 0;

// Scheduler queue with the tuple of end time and callback function - sorted by end time.
private _schedulerQueue: ScheduledFunction[] = [];
// Current simulated time in millis.
private _currentTime: number = 0;

constructor() {}

scheduleFunction(cb: Function, delay: number, args: any[] = [], id: number = -1) : number {
let currentId: number = id < 0 ? this.nextId++ : id;
let endTime = this._currentTime + delay;

// Insert so that scheduler queue remains sorted by end time.
let newEntry: ScheduledFunction = {
endTime: endTime,
id: currentId,
func: cb,
args: args,
delay: delay
}
};
let i = 0;
for (; i < this._schedulerQueue.length; i++) {
let currentEntry = this._schedulerQueue[i];
Expand All @@ -40,7 +40,7 @@
this._schedulerQueue.splice(i, 0, newEntry);
return currentId;
}

removeScheduledFunctionWithId(id: number): void {
for (let i = 0; i < this._schedulerQueue.length; i++) {
if (this._schedulerQueue[i].id == id) {
Expand All @@ -49,11 +49,11 @@
}
}
}

tick(millis: number = 0): void {
let finalTime = this._currentTime + millis;
while (this._schedulerQueue.length > 0) {
let current = this._schedulerQueue[0];
let current = this._schedulerQueue[0];
if (finalTime < current.endTime) {
// Done processing the queue since it's sorted by endTime.
break;
Expand All @@ -71,19 +71,19 @@
this._currentTime = finalTime;
}
}

class FakeAsyncTestZoneSpec implements ZoneSpec {
static assertInZone(): void {
if (Zone.current.get('FakeAsyncTestZoneSpec') == null) {
throw new Error('The code should be running in the fakeAsync zone to call this function');
}
}

private _scheduler: Scheduler = new Scheduler();
private _microtasks: Function[] = [];
private _lastError: Error = null;
private _uncaughtPromiseErrors: {rejection: any}[] = Promise[Zone['__symbol__']('uncaughtPromiseErrors')];

pendingPeriodicTimers: number[] = [];
pendingTimers: number[] = [];

Expand All @@ -95,52 +95,52 @@
completers: {onSuccess?: Function, onError?: Function}): Function {
return (...args): boolean => {
fn.apply(global, args);

if (this._lastError === null) { // Success
if (completers.onSuccess != null) {
completers.onSuccess.apply(global);
}
// Flush microtasks only on success.
this.flushMicrotasks();
} else { // Failure
if (completers.onError != null) {
if (completers.onError != null) {
completers.onError.apply(global);
}
}
// Return true if there were no errors, false otherwise.
// Return true if there were no errors, false otherwise.
return this._lastError === null;
}
};
}

private static _removeTimer(timers: number[], id:number): void {
let index = timers.indexOf(id);
if (index > -1) {
timers.splice(index, 1);
}
}

private _dequeueTimer(id: number): Function {
return () => {
FakeAsyncTestZoneSpec._removeTimer(this.pendingTimers, id);
};
}

private _requeuePeriodicTimer(
fn: Function, interval: number, args: any[], id: number): Function {
return () => {
// Requeue the timer callback if it's not been canceled.
if (this.pendingPeriodicTimers.indexOf(id) !== -1) {
this._scheduler.scheduleFunction(fn, interval, args, id);
}
}
};
}

private _dequeuePeriodicTimer(id: number): Function {
return () => {
FakeAsyncTestZoneSpec._removeTimer(this.pendingPeriodicTimers, id);
};
}

private _setTimeout(fn: Function, delay: number, args: any[]): number {
let removeTimerFn = this._dequeueTimer(this._scheduler.nextId);
// Queue the callback and dequeue the timer on success and error.
Expand All @@ -149,20 +149,20 @@
this.pendingTimers.push(id);
return id;
}

private _clearTimeout(id: number): void {
FakeAsyncTestZoneSpec._removeTimer(this.pendingTimers, id);
this._scheduler.removeScheduledFunctionWithId(id);
}

private _setInterval(fn: Function, interval: number, ...args): number {
let id = this._scheduler.nextId;
let completers = {onSuccess: null, onError: this._dequeuePeriodicTimer(id)};
let cb = this._fnAndFlush(fn, completers);
// Use the callback created above to requeue on success.

// Use the callback created above to requeue on success.
completers.onSuccess = this._requeuePeriodicTimer(cb, interval, args, id);

// Queue the callback and dequeue the periodic timer only on error.
this._scheduler.scheduleFunction(cb, interval, args);
this.pendingPeriodicTimers.push(id);
Expand All @@ -180,7 +180,7 @@
this._lastError = null;
throw error;
}

tick(millis: number = 0): void {
FakeAsyncTestZoneSpec.assertInZone();
this.flushMicrotasks();
Expand All @@ -197,7 +197,7 @@
// If there is an error stop processing the microtask queue and rethrow the error.
this._resetLastErrorAndThrow();
}
}
};
while (this._microtasks.length > 0) {
let microtask = this._microtasks.shift();
microtask();
Expand Down Expand Up @@ -249,10 +249,10 @@
return delegate.cancelTask(target, task);
}
}

onHandleError(parentZoneDelegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
error: any): boolean {
this._lastError = error;
this._lastError = error;
return false; // Don't propagate error to parent zone.
}
}
Expand Down
14 changes: 7 additions & 7 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ const Zone: ZoneType = (function(global: any) {
const zone: Zone = this;
return function() {
return zone.runGuarded(_callback, this, <any>arguments, source);
}
};
}

public run(callback: Function, applyThis: any = null, applyArgs: any[] = null,
Expand Down Expand Up @@ -755,7 +755,7 @@ const Zone: ZoneType = (function(global: any) {
if (this._scheduleTaskZS) {
return this._scheduleTaskZS.onScheduleTask(this._scheduleTaskDlgt, this.zone, targetZone, task);
} else if (task.scheduleFn) {
task.scheduleFn(task)
task.scheduleFn(task);
} else if (task.type == 'microTask') {
scheduleMicroTask(<MicroTask>task);
} else {
Expand Down Expand Up @@ -788,7 +788,7 @@ const Zone: ZoneType = (function(global: any) {
} else if (!task.cancelFn) {
throw new Error('Task does not support cancellation, or is already canceled.');
} else {
value = task.cancelFn(task)
value = task.cancelFn(task);
}
if (targetZone == this.zone) {
// this should not be in the finally block, because exceptions assume not canceled.
Expand Down Expand Up @@ -973,7 +973,7 @@ const Zone: ZoneType = (function(global: any) {
return (v) => {
resolvePromise(promise, state, v);
// Do not return value or you will break the Promise spec.
}
};
}

function resolvePromise(promise: ZoneAwarePromise<any>, state: boolean, value: any): ZoneAwarePromise<any> {
Expand Down Expand Up @@ -1053,9 +1053,9 @@ const Zone: ZoneType = (function(global: any) {
static race<R>(values: PromiseLike<any>[]): Promise<R> {
let resolve: (v: any) => void;
let reject: (v: any) => void;
let promise: any = new this((res, rej) => {resolve = res; reject = rej});
function onResolve(value) { promise && (promise = null || resolve(value)) }
function onReject(error) { promise && (promise = null || reject(error)) }
let promise: any = new this((res, rej) => {[resolve, reject] = [res, rej];});
function onResolve(value) { promise && (promise = null || resolve(value)); }
function onReject(error) { promise && (promise = null || reject(error)); }

for(let value of values) {
if (!isThenable(value)) {
Expand Down
2 changes: 1 addition & 1 deletion test/browser/WebSocket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (!window['soucelabs']) {
worker.onmessage = (e:MessageEvent) => {
expect(e.data).toBe('pass');
done();
}
};
});

it('should work with addEventListener', function (done) {
Expand Down
Loading

0 comments on commit ed87c26

Please sign in to comment.