本文整理匯總了TypeScript中rx.Observable.combineLatest方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.combineLatest方法的具體用法?TypeScript Observable.combineLatest怎麽用?TypeScript Observable.combineLatest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rx.Observable
的用法示例。
在下文中一共展示了Observable.combineLatest方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: model
function model(props$: Observable<RadioButtonProps>, actions: any) {
const clickedValue$ = Observable.combineLatest(
actions.itemMouseClick$, props$, (click, props) => props.value)
.do(x => console.log('clickedValue ' + x));
const radioGroupValue$ = Observable.just('RadioHard');
const checked$ = Observable.combineLatest(props$, clickedValue$, radioGroupValue$,
(props, clickedValue, radioGroupValue) => {
//TODO: does this stop having a disabled and checked, not just initial state?
return !props.disabled && (clickedValue === radioGroupValue);
})
.do(x => console.log('checked ' + x));
return combineLatestObj({clickedValue$, props$, checked$ });
}
示例2: formatDate
setDate: (startDate, endDate) => {
const daysInRange = [];
moment.range([startDate, endDate]).by('days', m => daysInRange.push(m));
const dates = Array.from(daysInRange.keys())
.map(i => formatDate(moment(startDate).add(i, 'days')))
.filter(date => moment(date).isSameOrBefore(moment(endDate)));
articles.update(dates);
articlesWithVideos.update(dates);
videosProduced.update(dates);
allMediaEvents.update(dates);
const mediaEventsDays = dates.map(allMediaEventsStat$);
const mediaEventsSub$ = Rx.Observable.combineLatest(...mediaEventsDays).subscribe(mediaEvents => {
// We shouldn't be sending these all over, but it gives us the flexibility in the template for now
const articles = addMediaEvents(mediaEvents.map(mediaEvent => mediaEvent.articles));
const fronts = addMediaEvents(mediaEvents.map(mediaEvent => mediaEvent.fronts));
const videoPages = addMediaEvents(mediaEvents.map(mediaEvent => mediaEvent.videoPages));
const total = addMediaEvents([articles, fronts, videoPages]);
mediaEvents$.onNext(mediaEvents);
mediaEventTotals$.onNext({total, articles, fronts, videoPages});
mediaEventsSub$.dispose();
});
}
示例3: update
function update(dates) {
const days = dates.map(stat$);
const sub$ = Rx.Observable.combineLatest(...days).subscribe(data => {
const total = data.reduce((prev, next) => prev + next.total, 0);
data$.onNext(data);
total$.onNext(total);
sub$.dispose();
});
}
示例4: view
function view(state$: Observable<any>, actions$: Observable<any>) {
return Observable
.combineLatest(
github$,
state$,
actions$.startWith(undefined),
(github, state, action) => ({ state: assign(state, { github }), action }))
.map((props: any) =>
React.createElement(App, props));
}
示例5: MediaEvent
export const allMediaEvents$ = date => {
const frontsTotal$ = getFrontsMediaEvents$(date).catch(() => new MediaEvent());
const pageTotal$ = getPageMediaEvents$(date).catch(() => new MediaEvent());
return Rx.Observable.combineLatest(frontsTotal$, pageTotal$, (frontsTotal, pageTotal) =>
({
date,
fronts: frontsTotal,
videoPages: pageTotal.videoPages,
articles: pageTotal.articlePages
}));
};
示例6: classNames
const vtree$ = props$.map( (props) => {
const $radioGroupSelectedValue = Observable.combineLatest(childrenValues, (...values) => {
return { itemMouseClick$ };
}).startWith(props.value)
.do(x => console.log('radioGroupSelectedValue ' + x));
const className = classNames('radioGroup', props.className);
return (
div( { props: { className }, attrs: { 'data-cycle-ui': 'radio-group' } },
childrenDOMs
)
);
});
示例7: getGameHighScores
let main = ({ bot }: Sources) => ({
bot: $.from([
$.just(sendGame(
{ chat_id: GROUP_ID,
game_short_name: 'test' },
{})),
bot.events('message')
.pluck<TcombUser>('message', 'from')
.do(() => bot.dispose())
.combineLatest<TcombMessage, MessageUser>(bot.responses.take(1), (user, message) => ({ message, user }))
.map(({ message, user }) =>
getGameHighScores(
{ user_id: user.id, message_id: message.message_id },
{ message })),
$.combineLatest<any, any, MessageUserScore>(
bot.responses
.take(1)
.combineLatest(bot.events('message').do(() => bot.dispose()).pluck('message', 'from')),
bot.responses
.skip(1)
.filter(Array.isArray)
.flatMap($.from),
([message, user], score) => ({ message, user, score }))
.filter(({user, score}) => user.id === score.user.id)
.map(({ score: { score }, user, message }) =>
setGameScore(
{ score: score + 1, user_id: user.id, message_id: message.message_id },
{ message })),
bot.responses
.skip(1)
.filter(prop('game'))
.pluck('game')
.do((game: TcombGame) => {
bot.dispose()
t.ok(Game.is(Game(game)), 'game satisfies typecheck')
t.end()
})
])
})