Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

RxJS Real World

RxJS Real World

2017/6/17 ng-japan 2017で発表した資料です。

OKUNOKENTARO

June 17, 2017
Tweet

More Decks by OKUNOKENTARO

Other Decks in Technology

Transcript

  1. Angular @Component Commands Service Queries Service Repository Service Server-side &WFSZUIJOHJTBTZODISPOPVTTUSFBN

    Sync call Sync call Sync request and async response Async stream Async stream
  2. HttpService ApiService Endpoint Cache Endpoint Map Authority Adapter HttpService ApiService

    Endpoint Endpoint Map w *OPSEFSUPLOPXBMMUIFFOEQPJOUT XFIBWFUPHFUUIFNBQQJOH JOBEWBODF w 8FXJMMQSPDFFEUPUIFOFYUQSPDFTTJOHCZVTJOHconcatMap() w "TZODISPOPVTMZDPNCJOFBSFRVFTUCPEZBOEUIFFOEQPJOU JOGPSNBUJPO
  3. HttpService ApiService Endpoint Cache Endpoint Map Authority Adapter HttpService ApiService

    Endpoint Endpoint Map this.endpoint .endpoint$ .concatMap(ep => this.http.get(ep.url))
  4. HttpService ApiService Endpoint Cache Endpoint Map Authority Adapter HttpService Endpoint

    Authority w 8FIBWFUPIBOEMFUIFQSFTFODFPS BCTFODFPGBDDFTTBVUIPSJUZ w 5IFTUSFBNJTUFNQPSBSJMZCSBODIFEVTJOH partition()BOEBDDFTT
 BVUIPSJUZJTTUPSFE w "OEXFNFSHFBHBJO
 CZVTJOHmerge()
  5. HttpService ApiService Endpoint Cache Endpoint Map Authority Adapter HttpService Endpoint

    Authority const streams = somethingStream$ .partition(authority => authority.isAllowed) const [allowed$, denied$] = streams return Observable.merge( allowed$ .map(res => ({isAllowed: true, data: res})), denied$ .map(authority => ({isAllowed: false, data: autority})) )
  6. HttpService ApiService Endpoint Cache Endpoint Map Authority Adapter HttpService ApiService

    Adapter w 5IFSFJTOPUZQFBOOPUBUJPOJOUIF SFTQPOTFGSPNUIFTFSWFS w "OEUIFQSPQFSUZOBNFNBZCFEJGpDVMUUP SFBE w 8FNBLFJUFBTZUPSFBECZQBTTJOHUIF BEBQUFSWJBconcatMap()
  7. HttpService ApiService Endpoint Cache Endpoint Map Authority Adapter HttpService ApiService

    Adapter this.wrapedHttp .get(inputModel) .concatMap(allowedOrDenied => { if (isFailure(allowedOrDenied)) { return this.denied() } const adaptedResponse = this.adapt(allowedOrDenied.data.json()) this.cache.set(cacheKey, adaptedResponse) return this.allowed(adaptedResponse) })
  8. HttpService ApiService Endpoint Cache Endpoint Map Authority Adapter ApiService Cache

    w 8FBSFQSPDFTTJOHFGpDJFOUSFRVFTUTVTJOHDBDIF w 5IFTFSWJDFTZODISPOPVTMZSFUVSOTUIFDBDIFJGJUFYJTUT w 8FVTFObservable.of()UPUSFBUTZODISPOPVTWBMVFT BTTUSFBNT
  9. HttpService ApiService Endpoint Cache Endpoint Map Authority Adapter HttpService ApiService

    Adapter const cacheKey = inputModel.toCacheKey() if (this.cache.has(cacheKey)) { return this.allowed(this.cache.get(cacheKey)) } return this.wrapedHttp .get(inputModel) .concatMap(allowedOrDenied => { // })
  10. /FTUFEDPNCJOF-BUFTU class SomeQueriesService { get methodB$(): Observable<[...]> { return Observable.combineLatest(

    this.methodA$, this.otherRepository.someModels$ ) } get methodA$(): Observable<[...]> { return Observable.combineLatest( this.repository.entities$, this.config.config$ ) } }
  11. class SomeQueriesService { get methodC$(): Observable<[...]> { return Observable.combineLatest( this.methodB$,

    this.greatRepository.niceValues$ ) } get methodB$(): Observable<[...]> { return Observable.combineLatest( this.methodA$, this.otherRepository.someModels$ ) } get methodA$(): Observable<[...]> { return Observable.combineLatest( this.repository.entities$, this.config.config$ ) } } /FTUFEDPNCJOF-BUFTUCFDPNFTWFSZDPNQMJDBUFE ,*44,FFQJUTIPSUBOETJNQMF