本文整理匯總了TypeScript中vs/base/common/winjs.base.TPromise.is方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript base.TPromise.is方法的具體用法?TypeScript base.TPromise.is怎麽用?TypeScript base.TPromise.is使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vs/base/common/winjs.base.TPromise
的用法示例。
在下文中一共展示了base.TPromise.is方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: handleVetos
export function handleVetos(vetos: (boolean | TPromise<boolean>)[], onError: (error: Error) => void): TPromise<boolean /* veto */> {
if (vetos.length === 0) {
return TPromise.as(false);
}
const promises: TPromise<void>[] = [];
let lazyValue = false;
for (let valueOrPromise of vetos) {
// veto, done
if (valueOrPromise === true) {
return TPromise.as(true);
}
if (TPromise.is(valueOrPromise)) {
promises.push(valueOrPromise.then(value => {
if (value) {
lazyValue = true; // veto, done
}
}, err => {
onError(err); // error, treated like a veto, done
lazyValue = true;
}));
}
}
return TPromise.join(promises).then(() => lazyValue);
}
示例2: function
type.prototype[methodName] = function(...param: any[]) {
if (!condition) {
return findThreadService(this).OneWorker(this, methodName, target, param, affinity);
} else {
let that = this,
promise = condition.call(that);
if (!TPromise.is(promise)) {
promise = TPromise.as(promise);
}
return promise.then(function() {
return findThreadService(that).OneWorker(that, methodName, target, param, affinity);
});
}
};
示例3:
renderer.code = (code, lang) => {
let value = options.codeBlockRenderer(lang, code);
if (typeof value === 'string') {
return value;
}
if (TPromise.is(value)) {
// when code-block rendering is async we return sync
// but update the node with the real result later.
const id = defaultGenerator.nextId();
TPromise.join([value, withInnerHTML]).done(values => {
let [value] = values;
let span = element.querySelector(`span[data-code="${id}"]`);
if (span) {
span.innerHTML = value;
}
}, err => {
// ignore
});
return `<span data-code="${id}">${code}</span>`;
}
return code;
};
示例4:
renderer.code = (code, lang) => {
const value = options.codeBlockRenderer(lang, code);
if (typeof value === 'string') {
return value;
}
if (TPromise.is(value)) {
// when code-block rendering is async we return sync
// but update the node with the real result later.
const id = defaultGenerator.nextId();
TPromise.join([value, withInnerHTML]).done(values => {
const strValue = values[0] as string;
const span = element.querySelector(`div[data-code="${id}"]`);
if (span) {
span.innerHTML = strValue;
}
}, err => {
// ignore
});
return `<div class="code" data-code="${id}">${escape(code)}</div>`;
}
return code;
};