當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Observable.fromPromise方法代碼示例

本文整理匯總了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);
}
開發者ID:RichiCoder1,項目名稱:omnisharp-atom,代碼行數:10,代碼來源:framework-provider.ts

示例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());
開發者ID:RichiCoder1,項目名稱:omnisharp-atom,代碼行數:10,代碼來源:omnisharp-atom-spec.ts

示例3: handlePromise

function handlePromise(output, done) {
    return Rx.Observable
        .fromPromise(output)
        .subscribe((val) => {
        }, err => {
            done(err);
        }, () => {
            done();
        });
}
開發者ID:Crossbow-js,項目名稱:crossbow,代碼行數:10,代碼來源:task.return.values.ts

示例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()
     ;
 });
開發者ID:Jason-Rev,項目名稱:json-schema-to-typescript,代碼行數:13,代碼來源:jsonSchemaTsCodegen.ts

示例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));
         })
     );
 }
開發者ID:lazyoft,項目名稱:ninjagoat,代碼行數:15,代碼來源:HttpClient.ts

示例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);
}
開發者ID:BloodyEnterprise,項目名稱:atom-json-schema,代碼行數:16,代碼來源:bower-provider.ts

示例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;
        }
        );

    }
開發者ID:rudijs,項目名稱:ng-docker,代碼行數:23,代碼來源:profile.controller.ts

示例8:

 .flatMap(() => Rx.Observable.fromPromise(AmqpLib.connect(url, options)))
開發者ID:cboden,項目名稱:rx-amqplib,代碼行數:1,代碼來源:RxAmqpLib.ts

示例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);
}
開發者ID:BloodyEnterprise,項目名稱:atom-json-schema,代碼行數:6,代碼來源:bower-provider.ts


注:本文中的rx.Observable.fromPromise方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。