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


TypeScript rxjs.Observable類代碼示例

本文整理匯總了TypeScript中@reactivex/rxjs.Observable的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable類的具體用法?TypeScript Observable怎麽用?TypeScript Observable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1:

 (data) => {
     return Rx.Observable.of({
         target: target,
         data: data,
         fileName: file.name
     });
 }
開發者ID:czcorpus,項目名稱:kontext,代碼行數:7,代碼來源:form.ts

示例2: Post

 () => {
   console.log('Users are saved!');
   const postPromises = posts.map(post => {
     const {userId, title, body} = post;
     return User.findOne({id: userId})
       .then(user => {
         const newPost = new Post({title, body, _creator: user._id});
         return newPost.save();
       })
       .then(newPost => {
         const postCommentsIndex = i + 10;
         for (i; i < postCommentsIndex && i < last; i++) {
           const {body, email} = comments[i];
           let newComment = new Comment({_post: newPost._id, body, email});
           return newComment.save();
         }
       });
   });
   let counter = 0;
   Rx.Observable
     .forkJoin(postPromises)
     .subscribe(
       () => null,
       (err) => console.log(`Err: ${err}`),
       () => {
         console.log('DB population is completed!');
         process.exit();
       }
     );
 }
開發者ID:malaman,項目名稱:other,代碼行數:30,代碼來源:pupulateDB.ts

示例3: to

  to(exchange: string, iO: Observable<any>): Subscription<any> {
    let channel, conn, cachedItems = [];
    let queue = uuid.v4();

    connect(this.config.connString)
    .then(c => conn = c && c.createChannel())
    .then(c => {
      channel = c;

      channel.assertExchange(exchange, 'fanout');
      cachedItems.forEach(item => {
        channel.publish(exchange, '', new Buffer(item));
      });
    })
    .catch(err => { throw err; });

    return iO
      .subscribe(
        msg => {
          if (!channel) {
            return cachedItems.push(msg);
          }

          channel.publish(exchange, '', new Buffer(msg));
        },
        err => console.error(`rabbitSink err, queue: ${queue}`, err),
        () => {
          if (conn) {
            channel.publish(exchange, '', new Buffer('__done'));
            conn.close()
          }
        }
      );
  }
開發者ID:jonesnc,項目名稱:gustav,代碼行數:34,代碼來源:GustavRabbit.ts

示例4: init

function init(state_: string, current_: number) {
  console.log('new');
  return Observable.fromPromise(new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve('init success');
    }, 2000);
  }));
}
開發者ID:taochunyu,項目名稱:learn,代碼行數:8,代碼來源:delay1.ts

示例5:

            this.action$ = this.inStream$.flatMap(v => {
                if (v instanceof Rx.Observable) {
                    return v;

                } else {
                    return Rx.Observable.from([v]);
                }
            }).share();
開發者ID:tomachalek,項目名稱:kontext,代碼行數:8,代碼來源:dispatcher.ts

示例6:

 .mergeMap(() => {
   return Rx.Observable.fromEvent($('.more'), 'click')
     .do((e)=>{
       const target = $(e.currentTarget)
       console.log(target.text(), path)
       location.href=(path + 'more/' + target.text())
     })
 })
開發者ID:gatinul,項目名稱:blog,代碼行數:8,代碼來源:blogList.ts

示例7: newValidationStatus

 (resp) => {
     const ans = newValidationStatus();
     ans.currPasswd = resp.fields.curr_passwd;
     ans.newPasswd = resp.fields.new_passwd;
     ans.newPasswd2 = resp.fields.new_passwd2;
     ans.messages = resp.messages.splice(0);
     return Rx.Observable.of(ans);
 }
開發者ID:czcorpus,項目名稱:kontext,代碼行數:8,代碼來源:profile.ts

示例8: to

  to(channelName: string, iO: Observable<any>): Subscription<any> {
    this.initChannel(channelName);

    return iO.subscribe(
      item => this.channels[channelName].forEach(fn => fn(item)),
      err => { throw err; },
      () => this.channels[channelName].forEach(fn => fn('__done'))
    );
  }
開發者ID:jonesnc,項目名稱:gustav,代碼行數:9,代碼來源:GustavMem.ts

示例9:

subs.subscribe(({connection, message:{symbol}}:any) => {
  const source = Observable.interval(500).map(() => ({
    symbol,
    price: Math.random() * 100,
    timestamp: Date.now()
  }));
  connection.streams = connection.streams || {};
  connection.streams[symbol] = source.subscribe(connection);
});
開發者ID:LongLiveCHIEF,項目名稱:aim,代碼行數:9,代碼來源:stock_server.ts

示例10: Error

 (data) => {
     console.log('data: ', data);
     if (data.lastpage && data.Items.length === 0) {
         throw new Error(this.layoutModel.translate('wordlist__page_not_found_err'));
     }
     this.data = this.importData(data.Items);
     this.isLastPage = !!data.lastpage;
     return Rx.Observable.of(data);
 }
開發者ID:czcorpus,項目名稱:kontext,代碼行數:9,代碼來源:main.ts


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