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);
      });
    }))
Example #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);
 });
Example #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;
       });
 });
Example #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);
  });
Example #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")
      }
    )

  }
Example #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();
      });
  });
Example #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);
            });
    });
    it('should return an observable', () => {
        const spy = jest.fn();

        class TestMatchMergeTransformer extends MatchMergeTransformer {
            match(o1, o2) {
                return o1 === o2;
            }

            merge(o1, o2) {
                return o1;
            }
        }

        const t = new TestMatchMergeTransformer();

        t.process(Observable.from([1, 2, 3, 2, 3]))
            .subscribe(spy, null, () => {
                expect(spy.mock.calls.length).toBe(3);
            });
    });
Example #12
0
/**
 * Created by 720718 on 2016/11/11.
 */

import * as Rx from 'rxjs/Rx';

const source = Rx.Observable.from([1, 2, 3]);

source.subscribe((data) => console.log('1st observer', data));
source.subscribe((data) => console.log('2nd observer', data));
source.subscribe((data) => {
    setTimeout(() => console.log('3rd observer', data), 1000);
});
setTimeout(() => {
    source.subscribe((data) => console.log('4th observer', data));
}, 5000);

const subject = new Rx.Subject();
subject.next(1);
subject.next(2);
subject.next(3);
subject.subscribe((data) => console.log('1st subject', data));
subject.subscribe((data) => console.log('2st subject', data));
subject.subscribe((data) => {
    setTimeout(() => console.log('3rd subject', data), 1000);
});
setTimeout(() => {
    subject.subscribe((data) => console.log('4th subject', data));
}, 5000);
subject.next(4);
subject.next(5);
Example #13
0
 public getCourseList() : Observable<string> {
     return Observable.from(["cources 1","cources 2","cources 3","cources 4","cources 5"]);
 }
Example #14
0
 adapt: (stream: Stream<any>) => Observable.from(stream),
Example #15
0
 public getTweet(id) {
     return Rx.Observable
         .from(this.cache)
         .filter((tweet:any) => tweet.id === id)
         .map(tweet => tweet);
 }
Example #16
0
 get() {
     return Observable.from([
         new Response(new ResponseOptions({ items: [{ style: 'foo', colour: 'bar', imgName: 'foo' }] }))
     ], () => {});
 }
const getSymbol$ = action$ => getSymbolArray$(action$).mergeMap((symbols: string[]) => Observable.from(symbols))
Example #18
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.from(new Promise((resolve, reject) => {
     resolve(1);
   }));
 });
Example #19
0
 before(() => setAdapt(stream => Observable.from(stream)));
Example #20
0
this.slides$          = this.slideCollection$.flatMap(c => Observable.from(c));
Example #21
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.from('foo');
 });
const createInputSeries: InputSeriesFactory<any> = createStateful
	.extend({
		get inputSeries(this: InputSeries<any, InputSeriesState<any>>) {
			return observables.get(this);
		}
	})
	.mixin({
		initialize<T>(
			instance: InputSeries<T, InputSeriesState<T>>,
			{ inputSeries }: InputSeriesOptions<T, InputSeriesState<T>> = {}
		) {
			if (inputSeries) {
				// Create an observable if the data option was provided.
				let observable: Observable<T[]>;
				if (isArrayLike(inputSeries)) {
					observable = Observable.from([ from(inputSeries) ]);
				}
				else if (isIterable(inputSeries)) {
					// The repetition is a workaround for <https://github.com/dojo/shim/issues/9>.
					observable = Observable.from([ from(inputSeries) ]);
				}
				else {
					observable = inputSeries;
				}
				observables.set(instance, observable);
				instance.emit({
					type: 'inputserieschange',
					observable,
					target: instance
				});
			}
 .catch((err) => {
     console.log(err); // dont do this, show user a nice message
     return Observable.from(err);
     // now we eat it, but only if the message is communicated to the user.
   });
        ... on Commit {
          history(first: 15, path: $path) {
            nodes {
              pushedDate
              message
            }
          }
        }
      }
    }
  }
}`;

let docFiles = getDocFilePaths(docsFolderPath);

let docNames = Observable.from(docFiles);

console.log("'Name','Review date','Commits since review','Score'");

docNames.subscribe(x => {
  let key = path.basename(x, ".md");

  if (!srcData[key])
    return;

  let vars = {
    "path": "lib/" + srcData[key].path
  };

  client.request(query, vars).then(data => {
      let nodes = data["repository"].ref.target.history.nodes;
Example #25
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.forkJoin(Rx.Observable.range(1, 2), Rx.Observable.from([4, 5]));
 });
Example #26
0
import {Observable} from 'rxjs/Rx';
import * as $ from 'jquery';

const body = $(document.body);
const output = $(`<div>Output</div>`);

Observable.from("Observables are lazy push collections :)".split(" "))
  .concatMap(word => Observable.of(word).delay(500))
  .repeat()
  .subscribe(word => body.html(word));

 public getProductObservable(id: number): Observable<Product> {
   return Observable.from(testProducts);
 }
Example #28
0
 .concatMap(names => Observable.from(names))
Example #29
0
function fromDictionary(dictionary) {
    return Rx.Observable.from(Object.keys(dictionary))
      .map(function(key){
        return dictionary[key];
      });
}
 public findUser(id: string): Observable<User> {
   return Observable.from(testUsers);
 }