本文整理汇总了TypeScript中@dojo/core/request/providers/xhr.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: loadText
/**
* Load a text resource
*/
function loadText(path: string): Task<any> {
return request(path).then(response => {
if (!response.ok) {
throw new Error('Request failed: ' + response.status);
}
return response.text();
});
}
开发者ID:jason0x43,项目名称:intern,代码行数:11,代码来源:util.ts
示例2: loadJson
export function loadJson(path: string, basePath?: string): Task<any> {
if (path[0] !== '/') {
basePath = basePath == null ? '/' : basePath;
path = `${basePath}${path}`;
}
return request(path).then(response => {
return response.text().then(text => {
return parseJSON(text);
});
});
}
开发者ID:bryanforbes,项目名称:intern,代码行数:11,代码来源:util.ts
示例3: _sendMessages
/**
* Some testing services have problems handling large message POSTs, so
* limit the maximum size of each POST body to maxPostSize bytes. Always
* send at least one message, even if it's more than maxPostSize bytes.
*/
protected _sendMessages(): Task<any> | undefined {
const messages = this._messageBuffer;
if (messages.length === 0) {
return;
}
const block = [messages.shift()!];
let size = block[0].message.length;
while (
messages.length > 0 &&
size + messages[0].message.length < this._maxPostSize
) {
size += messages[0].message.length;
block.push(messages.shift()!);
}
this._activeRequest = request(this.url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(block.map(entry => entry.message))
})
.then(response => {
if (response.status === 200) {
return response.json<any[]>();
} else if (response.status === 204) {
return [];
} else {
throw new Error(response.statusText);
}
})
.then((results: any[]) => {
block.forEach((entry, index) => {
entry.resolve(results[index]);
});
})
.catch(error => {
block.forEach(entry => {
entry.reject(error);
});
})
.finally(() => {
this._activeRequest = undefined;
if (messages.length > 0) {
return this._sendMessages();
}
});
return this._activeRequest;
}
开发者ID:gitgrimbo,项目名称:intern,代码行数:55,代码来源:Http.ts
示例4: request
const sendNextBlock = (): Task<any> => {
const block = [ messages.shift() ];
let size = block[0].length;
while (messages.length > 0 && size + messages[0].length < exports.maxPostSize) {
size += messages[0].length;
block.push(messages.shift());
}
return request(this.url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(block)
}).then(() => {
if (messages.length > 0) {
return sendNextBlock();
}
});
};
开发者ID:bryanforbes,项目名称:intern,代码行数:18,代码来源:Http.ts
示例5: _sendMessages
/**
* Some testing services have problems handling large message POSTs, so
* limit the maximum size of each POST body to maxPostSize bytes. Always
* send at least one message, even if it's more than maxPostSize bytes.
*/
protected _sendMessages(): Task<void> {
const messages = this._messageBuffer;
const block = [messages.shift()!];
let size = block[0].length;
while (
messages.length > 0 &&
size + messages[0].length < this._maxPostSize
) {
size += messages[0].length;
block.push(messages.shift()!);
}
return request(this.url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(block)
}).then(() => {
if (messages.length > 0) {
return this._sendMessages();
}
});
}
开发者ID:jason0x43,项目名称:intern,代码行数:28,代码来源:Http.ts
注:本文中的@dojo/core/request/providers/xhr.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论