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


TypeScript store-saga.whenAction函數代碼示例

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


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

示例1: Headers

 return saga$ => saga$  
 .filter(whenAction('LOAD_MAINTENANCE'))  
 .do( e => {console.log('saga LOAD_MAINTENANCE')})
 //.map( saga => {console.log('map');return saga.state.blob='x'} )
  
 .flatMap( (saga)=>{
     console.log('init post ',saga);
     var t=localStorage.getItem('token'); 
     if (t==null) return Observable.of(null);
     var h:Headers=new Headers();
     h.append('Authorization',t);
     
     const query=http.post('http://virtual2.ballistix.co.uk:8000/api/maintenance',JSON.stringify({type:''}),{headers:h});
 
       
 
     return query.map((e)=>e.json()).catch((e)=>{return Observable.of(null)});
    
 })
 
  
 .map(    
   (saga) => {
       if (saga==null) {
           console.log('no data.');
           return false
       };
       
       
       console.log('after=',saga.result);
     return {type:'LOADED_USER',payload:saga.result};   
   })//.delay(1)
開發者ID:JamesUlph,項目名稱:ng2-start,代碼行數:32,代碼來源:sagas.ts

示例2:

   return saga$=>saga$.filter(whenAction('LOGIN_REQUEST'))
   .do(e=>{console.log('login request ',e);
e.state.loading=true;
})
   //.delay(1000)
   .flatMap((saga)=>{
       console.log(saga);
        var data={username:saga.action.payload.username,password:saga.action.payload.password};
        console.log(saga.state);
       const query=http.post('http://virtual2.ballistix.co.uk:8000/api/token',JSON.stringify(data));
  
        return query.map(e=>e.json());
   })
   .map( res => {
     console.log(res);
     if (res.status==200){
         localStorage.setItem('token',res.token);
         return {type:'LOGIN_COMPLETE',payload:res.token};
     }
   })
   .catch(error => {
       console.log('error');
       return Observable.of(false);
   }
    )
開發者ID:JamesUlph,項目名稱:ng2-start,代碼行數:25,代碼來源:sagas.ts

示例3: someService

        return function someService(iteration$: Observable<any>) {
    return iteration$ .filter(whenAction(CREATE_AUDIODATA))
        .mergeMap((iteration) => {
            if(iteration.state.audioItem){
                 var trackURL = Object.keys(iteration.state.artists)
                                        .filter( x =>  {
                                               return iteration.state.artists[x].id  ===  iteration.state.audioItem.artistId})
                                          .map(x => {return iteration.state.artists[x]})[0].trackURL;

                return  DataLoadAPI.default.getTrack(trackURL)
                    .map((res) => {
                        console.log("createPlayListItem SAGA riteration.state.audioItem =", iteration.state.audioItem);
                        console.log("createPlayListItem SAGA res.audiodata audiobuffer =", res);
                        return {
                            type: ADD_AUDIOITEM_TO_PLAYLIST,
                            payload:  Object.assign({},
                                                    iteration.state.audioItem,
                                                    {artistAudioBuffer:res})
                        };
                    })
            }else{
               return iteration.state;

            }
        });
        }
開發者ID:willSonic,項目名稱:angular2-exp-ngrx,代碼行數:26,代碼來源:audiomachine.ts

示例4:

 return saga$ => saga$
     .filter(whenAction(REQUEST_PRODUCTS))
     .mergeMap(() => shop.default.getProducts(300))
     .map(res => {
         return {
             type: RECEIVED_PRODUCTS,
             payload: res
         };
     });
開發者ID:willSonic,項目名稱:ngrx-examples,代碼行數:9,代碼來源:shop.ts

示例5:

 return iteration$ => iteration$
      .filter(whenAction(REQUEST_ARTISTS))
      .mergeMap(()  => ArtistAPI.default.getArtists(300))
      .map(res => {
             return {
                 type: RECEIVED_ARTISTS,
                 payload: res
            };
      });
開發者ID:willSonic,項目名稱:angular2-exp-ngrx,代碼行數:9,代碼來源:audiomachine.ts

示例6: getUrlWithIds

 return saga$ => saga$
   .filter(whenAction(LOAD_PEOPLE_REQUEST))
   .mergeMap(
     saga$ => _appHttp
       .get('http://localhost:3100'+ getUrlWithIds('people', saga$.action.payload)),
     (saga$, payload) => generateResponse(
       payload,
       LOAD_PEOPLE_SUCCESS,
       LOAD_PEOPLE_FAIL,
       (res) => normalize(res, arrayOf(peopleSchema))
     )
   );
開發者ID:Lukinos,項目名稱:ngrx-example,代碼行數:12,代碼來源:people.sagas.ts

示例7: generateResponse

 return saga$ => saga$
   .filter(whenAction(LOAD_PERSON_REQUEST))
   .let(shouldLoad('people', 'payload'))
   .mergeMap(
     saga$ => _appHttp
       .get(`http://localhost:3100/people/${saga$.action.payload}`),
     (saga$, payload) => generateResponse(
       payload,
       LOAD_PERSON_SUCCESS,
       LOAD_PERSON_FAIL,
       (res) => normalize(res, peopleSchema)
     )
   );
開發者ID:Lukinos,項目名稱:ngrx-example,代碼行數:13,代碼來源:people.sagas.ts

示例8: playerServices

        return function playerServices(iteration$: Observable<any>) {
             return iteration$.filter(whenAction(PLAY_INITIATED))
                             .mergeMap((iteration) => {
                                 return  webAudioPlayer.loadAudio(iteration.action.payload)
                                        .map((res) => {
                                                 console.log("[audiomachine.ts] --loadAudioItem SAGA");
                                                 return {
                                                    type: PLAY_START,
                                                    payload: iteration.action.payload
                                                };
                                        })

             });
        };
開發者ID:willSonic,項目名稱:angular2-exp-ngrx,代碼行數:14,代碼來源:audiomachine.ts


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