当前位置: 首页>>代码示例>>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;未经允许,请勿转载。