當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Observable.zip方法代碼示例

本文整理匯總了TypeScript中rx.Observable.zip方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.zip方法的具體用法?TypeScript Observable.zip怎麽用?TypeScript Observable.zip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rx.Observable的用法示例。


在下文中一共展示了Observable.zip方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: makeSources

export function makeSources (state: Observable<TcombUpdatesState>): DriverSources {
  let updates = state
    .pluck<TcombUpdate[]>('updates')
    .map((u: TcombUpdate[]) => $.from(u))
    .switch()
    .share()

  let startDate = state
    .pluck('startDate')
    .share()

  return {
    message: $.zip(updates, startDate)
      .filter(([update]) => Message.is(update.message))
      .filter(([update, startDate]) => (startDate - update.message.date * 1000) <= 30000)
      .map(([update]) => update)
      .share(),

    inlineQuery: updates
      .filter(propIs(InlineQuery, 'inline_query'))
      .share(),

    chosenInlineResult: updates
      .filter(propIs(ChosenInlineResult, 'chosen_inline_result'))
      .share(),

    callbackQuery: updates
      .filter(propIs(CallbackQuery, 'callback_query'))
      .share()
  }
}
開發者ID:goodmind,項目名稱:cycle-telegram,代碼行數:31,代碼來源:sources.ts

示例2:

router.get('/article/:permalink', (req, res, next) => {
  var urlParts = req.params['permalink'].split("-");
  var articleSource = urlParts[urlParts.length - 2];  //Get the "source" value
  var articleId = urlParts[urlParts.length - 1];  //Get the article id

  var postRx;
  if (articleSource == "gh") {
    postRx = gitHubLoader.loadPostById(articleId);
  } else {
    postRx = bloggerLoader.loadPostById(articleId);
  }

  Observable.zip(postRx, tumblrLoader.loadTumblrData(),
    (post, tumblrPosts) => {
      return {
        article: post,
        tumblr: tumblrPosts
      };
    }).subscribe(result => {
      res.render('article', { 
        articlePost: result.article,
        tumbrlPosts: result.tumblr
      });
    }, 
    err => res.redirect("/"))
});
開發者ID:creativedrewy,項目名稱:creativedrewy.com,代碼行數:26,代碼來源:index.ts

示例3: drawChart

  const endDate = app.get('endDate');
  dateRange$.onNext({startDate, endDate});
});


// Write totals
articles.total$.subscribe(total => app.set('articlesTotal', total));
articlesWithVideos.total$.subscribe(total => app.set('articlesWithVideoTotal', total));
videosProduced.total$.subscribe(total => app.set('videosProducedTotal', total));
allMediaEvents.totals$.subscribe(totals => app.set('allMediaEventsTotals', totals));
mediaEventTotals$.subscribe(mediaEventTotals => app.set('mediaEventTotals', mediaEventTotals));


Rx.Observable.zip(
  articlesWithVideos.data$,
  articles.data$,
  videosProduced.data$,
  (articlesWithVideos, articles, videosProduced) =>
  ({articlesWithVideos, articles, videosProduced}))
  .subscribe(({articlesWithVideos, articles, videosProduced}) => {
  // TODO: zip
  drawChart('video-embeds', ['Day', 'Articles created, total', 'With video embedded', 'videos produced'], articles.map((article, i) => [
    article.date, articles[i].total, articlesWithVideos[i].total, videosProduced[i].total
  ]));
});

// Play graph
mediaEvents$.subscribe(mediaEvents => {
  drawChart('video-plays', ['Day', 'Starts in article', 'Starts in video pages', 'Starts on fronts'], mediaEvents.map(mediaEvent => [
    mediaEvent.date, mediaEvent.articles.plays, mediaEvent.videoPages.plays, mediaEvent.fronts.plays
  ]));
});
開發者ID:guardian,項目名稱:video-dashboard,代碼行數:32,代碼來源:app.ts


注:本文中的rx.Observable.zip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。