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


TypeScript Observable.from方法代碼示例

本文整理匯總了TypeScript中rxjs/Rx.Observable.from方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.from方法的具體用法?TypeScript Observable.from怎麽用?TypeScript Observable.from使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs/Rx.Observable的用法示例。


在下文中一共展示了Observable.from方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: return

    return Observable.forkJoin(books.map(book => {
      if (!book.idAttachmentCover) {
        console.log("No cover for card " + book.id)
        return Observable.from('');
      }

      return this._http.get("https://api.trello.com/1/card/" + book.id + "/attachments/" + book.idAttachmentCover, {
        headers: this.getHeaders()
      })
      .map(res => res.json())
      .map(attachment => {
        return (attachment.previews && attachment.previews.length !== 0) ?
          attachment.previews[0].url : '';
      })
      .map(url => {
        return {
          id: book.id,
          url,
        };
      })
      .catch((error: Response) => {
        console.log(JSON.stringify(error.json()));
        return Observable.throw(error);
      });
    }))
開發者ID:bamlab,項目名稱:book-of-the-month-nativescript,代碼行數:25,代碼來源:book-list.service.ts

示例2: beforeEach

    beforeEach(inject([Http], _http => {
      http = _http;

      spyOn(http, 'post').and.returnValue(Observable.from([
        new Response(new ResponseOptions({body: {token}}))
      ]));
    }));
開發者ID:Joe-noh,項目名稱:trav-front,代碼行數:7,代碼來源:auth.service.spec.ts

示例3:

 observable1 = constructorZone1.run(() => {
   const people = [
     {name: 'Sue', age: 25}, {name: 'Joe', age: 30}, {name: 'Frank', age: 25},
     {name: 'Sarah', age: 35}
   ];
   return Rx.Observable.from(people);
 });
開發者ID:jahtalab,項目名稱:zone.js,代碼行數:7,代碼來源:rxjs.Observable.collection.spec.ts

示例4: function

 observable1 = constructorZone1.run(() => {
   return Rx.Observable.forkJoin(
       Rx.Observable.range(1, 2), Rx.Observable.from([4, 5]), function(x, y) {
         expect(Zone.current.name).toEqual(constructorZone1.name);
         return x + y;
       });
 });
開發者ID:jahtalab,項目名稱:zone.js,代碼行數:7,代碼來源:rxjs.forkjoin.spec.ts

示例5: canActivate

 canActivate(): Observable<boolean> {
   return Observable.from(this.auth.authState)
     .take(1)
     .map(state => !!state)
     .do(authenticated => {
   if (!authenticated) this.router.navigate([ '/home' ]);
   })
 }
開發者ID:drpain,項目名稱:thatguy,代碼行數:8,代碼來源:auth.service.ts

示例6: it

  it('should set products property with the items returned from the server (Observable)', () => {
    spyOn(service, 'getProducts').and.returnValue(
      Observable.from([testProducts])
    );

    fixture.detectChanges();

    expect(component.products).toEqual(testProducts);
  });
開發者ID:tarangSachdev92,項目名稱:webinars,代碼行數:9,代碼來源:products.component.async.spec.ts

示例7: getDetail

 getDetail(todos: Show[]) {
   if (!todos) return Observable.of([]);
   return Observable.from(todos)
     .filter((todo) => todo.id ? true : false)
     .mergeMap((todo) => {
       return Observable.zip(
         this.detail(todo.id),
         this.newestEpisode(todo.id),
         (detail, episode) => ({ id: todo.id, todo, detail, episode }));
     })
     .toArray();
 }
開發者ID:zhaoyiyi,項目名稱:tv-todo,代碼行數:12,代碼來源:show.service.ts

示例8: constructor

  constructor() {
    this.source_A = new Rx.Subject();
    this.source_B = new Rx.Subject();
    const src_A = Rx.Observable.from(this.source_A)
                    .map((value)=>{return value +'--' });
    const src_B = Rx.Observable.from(this.source_B);
    const merged_src = Rx.Observable.merge(src_A, src_B)
                        .map((value)=>{ return value + '||||'});

    merged_src.subscribe(
      (value)=>{
        console.log("subscribe", value);
      },
      (error)=>{
        console.log(error)
      },
      ()=>{
        console.log("completed")
      }
    )

  }
開發者ID:morninng,項目名稱:angular2fire_chat,代碼行數:22,代碼來源:from-multiple-buttons.component.ts

示例9: it

  it('should be able to compose with let', (done: MochaDone) => {
    const expected = ['aa', 'bb'];
    let i = 0;

    const foo = (observable: Rx.Observable<string>) => observable.map((x: string) => x + x);

    Rx.Observable
      .from(['a', 'b'])
      .let(foo)
      .subscribe(function (x) {
        expect(x).to.equal(expected[i++]);
      }, (x) => {
        done(new Error('should not be called'));
      }, () => {
        done();
      });
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:17,代碼來源:let-spec.ts

示例10: it

    it('should return an observable', () => {
        const spy = jest.fn();

        const subt = {
            process(o) {
                return Observable.of(o);
            }
        }

        subt.process = jest.fn(subt.process);

        const t = new MapTransformer(subt);

        t.process(Observable.from([1]), 2)
            .subscribe(spy, null, () => {
                expect(spy.mock.calls.length).toBe(1);
                expect((subt.process as any).mock.calls.length).toBe(1);
            });
    });
開發者ID:smartive,項目名稱:proc-that,代碼行數:19,代碼來源:MapTransformer.spec.ts


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