本文整理汇总了TypeScript中bluebird.cast函数的典型用法代码示例。如果您正苦于以下问题:TypeScript cast函数的具体用法?TypeScript cast怎么用?TypeScript cast使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cast函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: loadRegistryInfo
// triggers the registry download if registry hasn't been downloaded yet
function loadRegistryInfo() {
const registryInfo = ExtensionManager.extensions[packageJson.name].registryInfo;
if (!registryInfo) {
return Promise.cast(ExtensionManager.downloadRegistry());
}
return Promise.resolve();
}
示例2: resolve
.then((_text) => {
let text = _text;
if (text === null) {
return resolve();
}
if (removeBom) {
// remove BOM - \uFEFF
text = text.replace(/\uFEFF/g, "");
}
if (normalizeLineEndings) {
// normalizes line endings
text = text.replace(/\r\n/g, "\n");
}
// process lines
const lines = text.split("\n");
if (lineNumbers) {
lineNumbers.forEach((lineNumber) => {
if (typeof lines[lineNumber] === "string") {
lines[lineNumber] = lines[lineNumber].replace(/\s+$/, "");
}
});
} else {
lines.forEach((ln, lineNumber) => {
if (typeof lines[lineNumber] === "string") {
lines[lineNumber] = lines[lineNumber].replace(/\s+$/, "");
}
});
}
// add empty line to the end, i've heard that git likes that for some reason
if (addEndlineToTheEndOfFile) {
const lastLineNumber = lines.length - 1;
if (lines[lastLineNumber].length > 0) {
lines[lastLineNumber] = lines[lastLineNumber].replace(/\s+$/, "");
}
if (lines[lastLineNumber].length > 0) {
lines.push("");
}
}
text = lines.join("\n");
return Promise.cast(FileUtils.writeText(fileEntry, text))
.catch((err) => {
ErrorHandler.logError("Wasn't able to clean whitespace from file: " + fullPath);
resolve();
throw err;
})
.then(() => {
// refresh the file if it's open in the background
DocumentManager.getAllOpenDocuments().forEach((doc) => {
if (doc.file.fullPath === fullPath) {
reloadDoc(doc);
}
});
// diffs were cleaned in this file
resolve();
});
});
示例3: Promise
return new Promise((resolve) => {
const folder = getProjectRoot();
// if we previously tried, assume nothing has changed
if (writeTestResults[folder]) {
return resolve(writeTestResults[folder]);
}
// create entry for temporary file
const fileEntry = FileSystem.getFileForPath(folder + ".bracketsGitTemp");
function finish(bool) {
// delete the temp file and resolve
fileEntry.unlink(() => {
writeTestResults[folder] = bool;
resolve(bool);
});
}
// try writing some text into the temp file
Promise.cast(FileUtils.writeText(fileEntry, ""))
.then(() => finish(true))
.catch(() => finish(false));
});
示例4: commitAllFiles
function commitAllFiles() {
// do not return anything here, core expects jquery promise
Promise.cast(CommandManager.execute("file.saveAll"))
.then(() => {
return Git2.resetIndex();
})
.then(() => {
return handleGitCommit(lastCommitMessage, false, COMMIT_MODE.ALL);
});
}
示例5: reloadDoc
export function reloadDoc(doc) {
return Promise.cast(FileUtils.readAsText(doc.file))
.then((text) => {
doc.refreshText(text, new Date());
})
.catch((err) => {
ErrorHandler.logError("Error reloading contents of " + doc.file.fullPath);
ErrorHandler.logError(err);
});
}
示例6: Promise
return new Promise((resolve, reject) => {
// FUTURE: maybe use git commit --file=-
const fileEntry = FileSystem.getFileForPath(Preferences.get("currentGitRoot") + ".bracketsGitTemp");
Promise.cast(FileUtils.writeText(fileEntry, message))
.then(() => {
args.push("-F", ".bracketsGitTemp");
return git(args);
})
.then((res) => fileEntry.unlink(() => resolve(res)))
.catch((err) => fileEntry.unlink(() => reject(err)));
});
示例7: function
ConfigBuilder.prototype.start = function(){
var current:any;
var _configBuilder:any = this;
current = Promise.cast();
return Promise.map(this.commands, function(callback:any) {
return current = current.then(function() {
return callback();
});
}).then(function() {
return start(_configBuilder.toJSON());
});
}
示例8: get
export function get() {
if (jsonPromise) {
return jsonPromise;
}
const readPromise = FileUtils.readAsText(FileSystem.getFileForPath(getPackageJsonPath()));
jsonPromise = Promise.cast(readPromise)
.then((content) => {
packageJson = JSON.parse(content);
return packageJson;
});
return jsonPromise;
}
示例9: refresh
FileSystem.resolve(Preferences.get("currentGitRoot") + file, (err, fileEntry) => {
if (err) {
ErrorHandler.showError(err, "Could not resolve file");
return;
}
Promise.cast(ProjectManager.deleteItem(fileEntry))
.then(() => {
refresh();
})
.catch((err2) => {
ErrorHandler.showError(err2, "File deletion failed");
});
});
示例10: lintFile
function lintFile(filename) {
const fullPath = Preferences.get("currentGitRoot") + filename;
let codeInspectionPromise;
try {
codeInspectionPromise = CodeInspection.inspectFile(FileSystem.getFileForPath(fullPath));
} catch (e) {
ErrorHandler.logError("CodeInspection.inspectFile failed to execute for file " + fullPath);
ErrorHandler.logError(e);
codeInspectionPromise = Promise.reject(e);
}
return Promise.cast(codeInspectionPromise);
}