本文整理汇总了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();
});
}
示例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);
});
});
}
示例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;
}
示例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();
}
});
};
示例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();
}
});
}