当前位置: 首页>>代码示例>>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;未经允许,请勿转载。