本文整理汇总了TypeScript中rxjs/Rx.Observable.merge方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.merge方法的具体用法?TypeScript Observable.merge怎么用?TypeScript Observable.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Rx.Observable
的用法示例。
在下文中一共展示了Observable.merge方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: todoItemDataFlow
export function todoItemDataFlow(intent: TodoItemIntent, todoProperty$: Observable<Todo>){
const editing$ = Observable.merge<boolean, boolean>(
intent.startEdit$.map(() => true),
intent.stopEdit$.map(() => false),
intent.cancelEdit$.map(() => false)
).startWith(false);
const viewModel$ = todoProperty$
.combineLatest(editing$, (todoProperty, editing) => Object.assign({}, todoProperty, { editing }));
const delete$ = intent.delete$
.withLatestFrom(todoProperty$, (_, todo: Todo) => todo)
.map(x => ({ id: x.id }));
const edit$ = intent.stopEdit$
.withLatestFrom(todoProperty$, (title: string, todo: Todo) => ({ title, todo }))
.filter(x => x.title !== x.todo.title)
.map(x => ({ id: x.todo.id, title: x.title }));
const toggle$ = intent.toggleTodo$
.withLatestFrom(todoProperty$, (_, todo: Todo) => todo)
.map(todo => ({ id: todo.id }));
return {
viewModel$,
delete$,
edit$,
toggle$
};
}
示例2:
// 全てのStoreのStateUpdateをComponentに通知する。
// Componentはこのストリームを受けてcd.markForCheck()すればOnPush環境でViewを動的に更新できる。
get storeNotificator$$() {
// return this.mainStore.takeLatest$(_NOTIFICATION_);
const observables = this.stores.map(store => store.takeLatest$<any>(_NOTIFICATION_));
return Observable
.merge(...observables);
// .debounceTime(10); // あまり細かくストリームを流す必要もないのでdebounceTime
}
示例3: getEvent
/**
*
* @param eventId string
* Get event informations
*/
getEvent(eventId): Observable<any> {
const cacheKey: string = 'event_' + eventId;
let cacheStream = this.cache.getCache(cacheKey);
let webStream = this.storage.getValue('id').switchMap(id => {
return this.http.get(this.baseUrl + '/chillers/' + id + '/events/' + eventId)
.map(res => res.json())
.filter(res => res)
.map(res => {
if (res.chillerid == id) {
res.mine = true;
} else {
res.mine = false;
}
return res;
})
.map(res => {
this.cache.setCache(cacheKey, res);
return res;
});
});
return Observable.merge(cacheStream, webStream)
.filter(res => res);
}
示例4:
select<T extends Component, T2 extends Component>(v1: Type<T>, v2: Type<T2>): Rx.Observable<[T,T2]> {
let r1 = Rx.Observable.of(...this.state.getComponentMap(v1).values());
let r2 = Rx.Observable.of(...this.state.getComponentMap(v2).values());
return Rx.Observable
.merge<T,T2>(r1, r2)
.groupBy(c => c.entityId)
.flatMap(group => group.reduce((acc, curr) => [...acc, curr], []))
.filter(a => a.length === 2);
}
示例5:
.flatMap(i => {
let j1 = Observable.create(s => {
$.get("http://localhost:8080/double?number=" + (i), d => s.next(d));
});
let j2 = Observable.create(s => {
$.get("http://localhost:8080/double?number=" + (i + 100), d => s.next(d));
});
let j3 = Observable.create(s => {
$.get("http://localhost:8080/double?number=" + (i + 1000000), d => s.next(d));
});
return Observable.merge(j1, j2, j3);
})
示例6: fromDictionary
selects<T extends Component, T2 extends Component>(v1: Type<T>, v2: Type<T2>): Rx.Observable<[T,T2]> {
let r1 = fromDictionary(this.state.getComponentMap(v1));
let r2 = fromDictionary(this.state.getComponentMap(v2));
return Rx.Observable
.merge<T,T2>(r1, r2)
.groupBy(c => c.entityId)
.flatMap(group => group.reduce((acc, curr) => [...acc, curr], []))
.filter(arr => arr.length === 2)
.map(arr => {
return [arr[0], arr[1]]
})
}
示例7: createExecuteTradeResponse
.subscribe(limitCheckResult => {
if (limitCheckResult) {
const request = serviceClient
.createRequestResponseOperation(
'executeTrade',
executeTradeRequest
)
.publish()
.refCount()
disposables.add(
Observable.merge(
request
.map(dto => {
const trade = tradeMapper.mapFromTradeDto(dto.Trade)
log.info(
`execute response received for: ${executeTradeRequest}. Status: ${trade.status}`,
dto
)
return createExecuteTradeResponse(trade)
})
// if we never receive a response, mark request as complete
.timeout(
EXECUTION_REQUEST_TIMEOUT_MS,
Scheduler.asap.schedule(() =>
createExecuteTradeResponseForError(
'Trade execution timeout exceeded',
executeTradeRequest
)
)
),
// show timeout error if request is taking longer than expected
Observable.timer(EXECUTION_CLIENT_TIMEOUT_MS)
.map(() =>
createExecuteTradeResponseForError(
'Trade execution timeout exceeded',
executeTradeRequest
)
)
.takeUntil(request)
).subscribe(o)
)
} else {
o.next(
createExecuteTradeResponseForError(
'Credit limit exceeded',
executeTradeRequest
)
)
}
})
示例8: getProfileId
/**
*
* Return the profile id: number
*/
getProfileId(): Observable<any> {
let id = this.storage.getValue('id')
.filter(id => id)
.switchMap(id => {
return this.http.get(this.baseUrl + '/chillers/' + id)
.map(res => res.json())
.filter(res => res)
.map(res => {
return id;
});
}
);
return Observable.merge(id)
.filter(res => res);
}
示例9: jQuery
jQuery.getJSON(url, ()=> {
var path = `https://${source}/Snapshots/business${businessId}/station${stationId}/${fileName}.jpg`;
jQuery(this.elRef.nativeElement).find('.newImage').fadeOut(200);
var img = this.renderer.createElement(this.elRef.nativeElement, 'img', null);
jQuery(img).addClass('snap');
var int$ = Observable.interval(500).do(()=> {
img.src = path;
})
var $err = Observable.fromEvent(img, 'error').do(()=>{
jQuery(this.elRef.nativeElement).find('.snap').remove();
})
var load$ = Observable.fromEvent(img, 'load')
var subscription = Observable.merge(int$, $err).takeUntil(load$).delay(500).subscribe((res)=> {
subscription.unsubscribe();
})
});
示例10: getChill
/**
*
* @param id string
* Get chill information when editing
*/
getChill(id): Observable<any> {
const cacheKey: string = 'chill_' + id;
let cacheStream = this.cache.getCache(cacheKey);
let webStream = this.http.get(this.baseUrl + '/chills/' + id)
.map(res => res.json())
.filter(res => res)
.map(res => {
this.cache.setCache(cacheKey, res);
return res;
});
return Observable.merge(cacheStream, webStream)
.filter(res => res);
}