Skip to content

Commit

Permalink
Adopt Promise.as => TPromise.as
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Feb 5, 2016
1 parent 578d067 commit c4e15e3
Show file tree
Hide file tree
Showing 93 changed files with 443 additions and 441 deletions.
6 changes: 3 additions & 3 deletions src/vs/base/browser/ui/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import 'vs/css!./dropdown';
import {Builder, $} from 'vs/base/browser/builder';
import {Promise} from 'vs/base/common/winjs.base';
import {TPromise} from 'vs/base/common/winjs.base';
import {Gesture, EventType} from 'vs/base/browser/touch';
import {ActionRunner, IAction} from 'vs/base/common/actions';
import {ActionBar, ActionItem, IActionItem} from 'vs/base/browser/ui/actionbar/actionbar';
Expand Down Expand Up @@ -193,7 +193,7 @@ export class Dropdown extends BaseDropdown {

export interface IContextMenuDelegate {
getAnchor(): any;
getActions(): Promise;
getActions(): TPromise<IAction[]>;
getActionItem?(action: IAction): IActionItem;
getActionsContext?(): any;
getMenuClassName?(): string;
Expand Down Expand Up @@ -267,7 +267,7 @@ export class DropdownMenu extends BaseDropdown {

this._contextMenuProvider.showContextMenu({
getAnchor: () => this.$el.getHTMLElement(),
getActions: () => Promise.as(this.actions),
getActions: () => TPromise.as(this.actions),
getActionsContext: () => this.menuOptions ? this.menuOptions.context : null,
getActionItem: (action) => this.menuOptions && this.menuOptions.actionItemProvider ? this.menuOptions.actionItemProvider(action) : null,
getMenuClassName: () => this.menuClassName,
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/browser/ui/dropdown/linksDropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import {Promise} from 'vs/base/common/winjs.base';
import {TPromise} from 'vs/base/common/winjs.base';
import {isMacintosh} from 'vs/base/common/platform';
import {isFunction} from 'vs/base/common/types';
import {Action} from 'vs/base/common/actions';
Expand Down Expand Up @@ -49,7 +49,7 @@ export class LinkDropdownAction extends Action {
window.location.href = urlString;
}

return Promise.as(true);
return TPromise.as(true);
});
}
}
2 changes: 1 addition & 1 deletion src/vs/base/browser/ui/messagelist/messageList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class MessageList {
}

(action.run() || TPromise.as(null))
.then(null, error => this.showMessage(Severity.Error, error))
.then<any>(null, error => this.showMessage(Severity.Error, error))
.done((r) => {
if (r === false) {
return;
Expand Down
6 changes: 3 additions & 3 deletions src/vs/base/browser/ui/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import 'vs/css!./toolbar';
import nls = require('vs/nls');
import {Promise} from 'vs/base/common/winjs.base';
import {TPromise} from 'vs/base/common/winjs.base';
import {IDisposable} from 'vs/base/common/lifecycle';
import {Builder, $} from 'vs/base/browser/builder';
import types = require('vs/base/common/types');
Expand Down Expand Up @@ -144,10 +144,10 @@ class ToggleMenuAction extends Action {
this.toggleDropdownMenu = toggleDropdownMenu;
}

public run(): Promise {
public run(): TPromise<any> {
this.toggleDropdownMenu();

return Promise.as(true);
return TPromise.as(true);
}

public get menuActions() {
Expand Down
20 changes: 10 additions & 10 deletions src/vs/base/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import {Promise} from 'vs/base/common/winjs.base';
import {TPromise} from 'vs/base/common/winjs.base';
import { IEventEmitter, EventEmitter, ListenerCallback, IBulkListenerCallback, ListenerUnbind } from 'vs/base/common/eventEmitter';
import {IDisposable} from 'vs/base/common/lifecycle';
import * as Events from 'vs/base/common/events';
Expand All @@ -16,11 +16,11 @@ export interface IAction extends IDisposable {
class: string;
enabled: boolean;
checked: boolean;
run(event?: any): Promise;
run(event?: any): TPromise<any>;
}

export interface IActionRunner extends IEventEmitter {
run(action: IAction, context?: any): Promise;
run(action: IAction, context?: any): TPromise<any>;
}

export interface IActionItem extends IEventEmitter {
Expand Down Expand Up @@ -61,7 +61,7 @@ export function isAction(thing: any): thing is IAction {
}

export interface IActionCallback {
(event: any): Promise;
(event: any): TPromise<any>;
}

export interface IActionProvider {
Expand Down Expand Up @@ -190,11 +190,11 @@ export class Action extends EventEmitter implements IAction {
this._actionCallback = value;
}

public run(event?: any): Promise {
public run(event?: any): TPromise<any> {
if (this._actionCallback !== null) {
return this._actionCallback(event);
} else {
return Promise.as(true);
return TPromise.as(true);
}
}
}
Expand Down Expand Up @@ -241,7 +241,7 @@ class ProxyAction extends Action implements IEventEmitter {
this.delegate.checked = value;
}

public run(event?: any): Promise {
public run(event?: any): TPromise<any> {
this.runHandler(event);
return this.delegate.run(event);
}
Expand Down Expand Up @@ -275,14 +275,14 @@ export interface IRunEvent {

export class ActionRunner extends EventEmitter implements IActionRunner {

public run(action: IAction, context?: any): Promise {
public run(action: IAction, context?: any): TPromise<any> {
if (!action.enabled) {
return Promise.as(null);
return TPromise.as(null);
}

this.emit(Events.EventType.BEFORE_RUN, { action: action });

return Promise.as(action.run(context)).then((result: any) => {
return TPromise.as(action.run(context)).then((result: any) => {
this.emit(Events.EventType.RUN, <IRunEvent>{ action: action, result: result });
}, (error: any) => {
this.emit(Events.EventType.RUN, <IRunEvent>{ action: action, error: error });
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/common/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export function sequence<T>(promiseFactory: ITask<TPromise<T>>[]): TPromise<T[]>
return TPromise.as(results);
}

return Promise.as(null).then(thenHandler);
return TPromise.as(null).then(thenHandler);
}

export interface IFunction<A, R> {
Expand Down
4 changes: 3 additions & 1 deletion src/vs/base/common/winjs.base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export interface ProgressCallback {
export declare class Promise {
constructor(init:(complete:ValueCallback, error:ErrorCallback, progress:ProgressCallback)=>void, oncancel?: any);

static as(value:any):Promise;
// commented out to speed up adoption of TPromise
// static as(value:any):Promise;

static join(promises:{[name:string]:Promise;}):Promise;
static join(promises:Promise[]):Promise;
static any(promises:Promise[]):Promise;
Expand Down
10 changes: 5 additions & 5 deletions src/vs/base/parts/quickopen/browser/quickOpenViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import {Promise} from 'vs/base/common/winjs.base';
import {TPromise} from 'vs/base/common/winjs.base';
import {isFunction} from 'vs/base/common/types';
import {ITree, IRenderer, IFilter, IDataSource, IAccessibilityProvider} from 'vs/base/parts/tree/browser/tree';
import {IModel} from 'vs/base/parts/quickopen/common/quickOpen';
Expand Down Expand Up @@ -36,13 +36,13 @@ export class DataSource implements IDataSource {
return model && model === element && model.entries.length > 0;
}

getChildren(tree: ITree, element: any): Promise {
getChildren(tree: ITree, element: any): TPromise<any[]> {
const model = this.modelProvider.getModel();
return Promise.as(model === element ? model.entries : []);
return TPromise.as(model === element ? model.entries : []);
}

getParent(tree: ITree, element: any): Promise {
return Promise.as(null);
getParent(tree: ITree, element: any): TPromise<any> {
return TPromise.as(null);
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/vs/base/parts/tree/browser/treeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export class Item extends Events.EventEmitter {

public expand(): WinJS.Promise {
if (this.isExpanded() || !this.doesHaveChildren || this.lock.isLocked(this)) {
return WinJS.Promise.as(false);
return WinJS.TPromise.as(false);
}

var result = this.lock.run(this, () => {
Expand All @@ -290,7 +290,7 @@ export class Item extends Events.EventEmitter {
if (this.needsChildrenRefresh) {
result = this.refreshChildren(false, true, true);
} else {
result = WinJS.Promise.as(null);
result = WinJS.TPromise.as(null);
}

return result.then(() => {
Expand All @@ -316,7 +316,7 @@ export class Item extends Events.EventEmitter {

public collapse(recursive: boolean = false): WinJS.Promise {
if (recursive) {
var collapseChildrenPromise = WinJS.Promise.as(null);
var collapseChildrenPromise = WinJS.TPromise.as(null);
this.forEachChild((child) => {
collapseChildrenPromise = collapseChildrenPromise.then(() => child.collapse(true));
});
Expand All @@ -325,7 +325,7 @@ export class Item extends Events.EventEmitter {
});
} else {
if (!this.isExpanded() || this.lock.isLocked(this)) {
return WinJS.Promise.as(false);
return WinJS.TPromise.as(false);
}

return this.lock.run(this, () => {
Expand All @@ -334,7 +334,7 @@ export class Item extends Events.EventEmitter {
this._setExpanded(false);
this.emit('item:collapsed', eventData);

return WinJS.Promise.as(true);
return WinJS.TPromise.as(true);
});
}
}
Expand Down Expand Up @@ -373,7 +373,7 @@ export class Item extends Events.EventEmitter {
private refreshChildren(recursive: boolean, safe: boolean = false, force: boolean = false): WinJS.Promise {
if (!force && !this.isExpanded()) {
this.needsChildrenRefresh = true;
return WinJS.Promise.as(this);
return WinJS.TPromise.as(this);
}

this.needsChildrenRefresh = false;
Expand All @@ -386,7 +386,7 @@ export class Item extends Events.EventEmitter {
if (this.doesHaveChildren) {
childrenPromise = this.context.dataSource.getChildren(this.context.tree, this.element);
} else {
childrenPromise = WinJS.Promise.as([]);
childrenPromise = WinJS.TPromise.as([]);
}

return childrenPromise.then((elements: any[]) => {
Expand Down Expand Up @@ -422,7 +422,7 @@ export class Item extends Events.EventEmitter {
return child.doRefresh(recursive, true);
}));
} else {
return WinJS.Promise.as(null);
return WinJS.TPromise.as(null);
}
}).then(() => {
this.emit('item:childrenRefreshed', eventData);
Expand Down Expand Up @@ -824,7 +824,7 @@ export class TreeModel extends Events.EventEmitter {
var item = this.getItem(element);

if (!item) {
return WinJS.Promise.as(null);
return WinJS.TPromise.as(null);
}

var eventData: IRefreshEvent = { item: item, recursive: recursive };
Expand All @@ -848,7 +848,7 @@ export class TreeModel extends Events.EventEmitter {
var item = this.getItem(element);

if (!item) {
return WinJS.Promise.as(false);
return WinJS.TPromise.as(false);
}

return item.expand();
Expand Down Expand Up @@ -877,7 +877,7 @@ export class TreeModel extends Events.EventEmitter {
var item = this.getItem(element);

if (!item) {
return WinJS.Promise.as(false);
return WinJS.TPromise.as(false);
}

return item.collapse(recursive);
Expand Down Expand Up @@ -933,7 +933,7 @@ export class TreeModel extends Events.EventEmitter {

public reveal(element: any, relativeTop: number = null): WinJS.Promise {
return this.resolveUnknownParentChain(element).then((chain: any[]) => {
var result = WinJS.Promise.as(null);
var result = WinJS.TPromise.as(null);

chain.forEach((e) => {
result = result.then(() => this.expand(e));
Expand All @@ -952,7 +952,7 @@ export class TreeModel extends Events.EventEmitter {
private resolveUnknownParentChain(element: any): WinJS.Promise {
return this.context.dataSource.getParent(this.context.tree, element).then((parent) => {
if (!parent) {
return WinJS.Promise.as([]);
return WinJS.TPromise.as([]);
}

return this.resolveUnknownParentChain(parent).then((result) => {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/base/parts/tree/test/browser/treeModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class TestDataSource implements _.IDataSource {
}

public getChildren(tree, element):WinJS.Promise {
return WinJS.Promise.as(element.children);
return WinJS.TPromise.as(element.children);
}

public getParent(tree, element):WinJS.Promise {
Expand Down Expand Up @@ -1147,10 +1147,10 @@ class DynamicModel extends Events.EventEmitter implements _.IDataSource {

public getChildren(tree, element):WinJS.Promise {
this.emit('getChildren', element);
var result = this.promiseFactory ? this.promiseFactory() : WinJS.Promise.as(null);
var result = this.promiseFactory ? this.promiseFactory() : WinJS.TPromise.as(null);
return result.then(() => {
this.emit('gotChildren', element);
return WinJS.Promise.as(this.data[element]);
return WinJS.TPromise.as(this.data[element]);
});
}

Expand Down Expand Up @@ -1662,7 +1662,7 @@ suite('TreeModel - bugs', () => {
getChildren: (_, e) => {
if (e === 'root') { return getRootChildren(); }
if (e === 'bart') { return getBartChildren(); }
return WinJS.Promise.as([]);
return WinJS.TPromise.as([]);
},
getParent: (_, e): WinJS.Promise => { throw new Error('not implemented'); },
}
Expand Down
Loading

0 comments on commit c4e15e3

Please sign in to comment.