zoukankan      html  css  js  c++  java
  • [RxJS] Avoid mulit post requests by using shareReplay()

    With the shareReplay operator in place, we would no longer fall into the situation where we have accidental multiple HTTP requests.

    And this covers the main use cases for doing the most typical read and modification operations, that we would implement while doing a custom REST API.

    import 'rxjs/add/operator/shareReplay';
    
      signUp(email: string, password: string) {
        return this.http.post<User>('/api/signup', {
          email,
          password
        }).shareReplay() // make sure that request was cached and it return observable
          .do((user) => this.subject.next(user));
      }

    shareReplay was added to RxJS V5.4

    More informaiton about shareReplay.

  • 相关阅读:
    Linux进程间通信(IPC)
    mq_setattr
    mq_getattr
    mq_unlink
    mq_receive
    mq_send
    mq_close
    POSIX消息队列
    mq_open
    C语言关键字
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7266513.html
Copyright © 2011-2022 走看看