本文整理匯總了TypeScript中rx.Observable.fromPromise方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.fromPromise方法的具體用法?TypeScript Observable.fromPromise怎麽用?TypeScript Observable.fromPromise使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rx.Observable
的用法示例。
在下文中一共展示了Observable.fromPromise方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: fetchFrameworkFromGithub
function fetchFrameworkFromGithub(framework: string) {
if (frameworkCache.has(framework)) {
return Observable.just<{ [key: string]: string }>(frameworkCache.get(framework));
}
// Get the file from github
var result = ajax(`https://raw.githubusercontent.com/OmniSharp/omnisharp-nuget/resources/frameworks/${framework.toLowerCase() }.json`).then(res => JSON.parse(res));
return Observable.fromPromise<{ [key: string]: string }>(result);
}
示例2: waitsForPromise
waitsForPromise(() =>
Observable.fromPromise(atom.workspace.open('simple/project.json'))
.flatMap(editor =>
ClientManager.getClientForEditor(editor))
.flatMap(x =>
x.state.startWith(x.currentState))
.where(z =>
z === DriverState.Connected)
.take(1)
.toPromise());
示例3: handlePromise
function handlePromise(output, done) {
return Rx.Observable
.fromPromise(output)
.subscribe((val) => {
}, err => {
done(err);
}, () => {
done();
});
}
示例4: it
it('test fetching multiple schema files', () => {
return Rx.Observable.fromPromise(readDirAsPromise(schemaDir))
.flatMap(x => x)
.filter(filename => /\.json$/.test(filename))
.map(filename => `file:/${schemaDir}/${filename}`)
// .tap(filename => { console.log(filename); })
.flatMap(filename => fetchSchemaAsPromise(filename))
// Note: the files can come back out of order.
// .tap(schema => { console.log(schema.title); })
.tap(schema => { assert.isString(schema.title); })
.toPromise()
;
});
示例5: performNetworkCall
private performNetworkCall(url:string, method:string, body?:any, headers?:HttpHeaders):Rx.IObservable<HttpResponse> {
return Rx.Observable.fromPromise(
window.fetch(url, {
method: method,
body: body,
headers: headers
}).then(response => {
let headers:HttpHeaders = {};
response.headers.forEach((value, name) => {
headers[name] = value;
});
return response.json().then(json => new HttpResponse(json, headers));
})
);
}
示例6: searchPackage
function searchPackage(text, name: string) {
var $get = fetch(`https://bower.herokuapp.com/packages/${name}`);
var toJson = (res: IResult) => res.json<BowerResult>();
var getReleases = (res: BowerResult) => {
if (!_.contains(res.url, 'github')) {
return;
}
var url = res.url.replace('.git', '/tags').replace('git://github.com/', 'https://api.github.com/repos/');
return fetch(url);
};
var getTags = (rel: GitHubTag) => rel.name.replace('v', '');
return Observable
.fromPromise<GitHubTag[]>($get.then(toJson).then(getReleases).then(res => res.json<GitHubTag[]>()))
.flatMap(Observable.fromArray)
.map(getTags);
}
示例7: constructor
constructor(
private auth: auth0.angular.IAuth0Service,
private $http: ng.IHttpService
) {
this.profile = this.auth.profile;
// console.log(101, auth.profile);
// console.log(201, auth.getProfile());
Rx.Observable.fromPromise($http({
url: 'https://api.github.com/users/rudijs',
method: 'GET'
})).subscribe(
function(data: any) {
console.log('data', data);
// $scope.data = data;
},
function(err: any) {
console.log('err', err);
// $scope.error = err.message;
}
);
}
示例8:
.flatMap(() => Rx.Observable.fromPromise(AmqpLib.connect(url, options)))
示例9: search
function search(text) {
var $get = fetch(`https://bower.herokuapp.com/packages/search/${text}`);
return Observable
.fromPromise<BowerResult[]>($get.then(res => res.json<BowerResult[]>()))
.flatMap<BowerResult>(Observable.fromArray);
}