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);
      });
    }))
Ejemplo n.º 2
0
    beforeEach(inject([Http], _http => {
      http = _http;

      spyOn(http, 'post').and.returnValue(Observable.from([
        new Response(new ResponseOptions({body: {token}}))
      ]));
    }));
 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);
 });
Ejemplo n.º 4
0
 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;
       });
 });
Ejemplo n.º 5
0
 canActivate(): Observable<boolean> {
   return Observable.from(this.auth.authState)
     .take(1)
     .map(state => !!state)
     .do(authenticated => {
   if (!authenticated) this.router.navigate([ '/home' ]);
   })
 }
  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);
  });
Ejemplo n.º 7
0
 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();
 }
  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")
      }
    )

  }
Ejemplo n.º 9
0
  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();
      });
  });
Ejemplo n.º 10
0
    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);
            });
    });