本文整理汇总了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);
});
}))
示例2: beforeEach
beforeEach(inject([Http], _http => {
http = _http;
spyOn(http, 'post').and.returnValue(Observable.from([
new Response(new ResponseOptions({body: {token}}))
]));
}));
示例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);
});
示例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;
});
});
示例5: canActivate
canActivate(): Observable<boolean> {
return Observable.from(this.auth.authState)
.take(1)
.map(state => !!state)
.do(authenticated => {
if (!authenticated) this.router.navigate([ '/home' ]);
})
}
示例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);
});
示例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();
}
示例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")
}
)
}
示例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();
});
});
示例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);
});
});