本文整理汇总了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)
示例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);
}
)
示例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;
}
});
}
示例4:
return saga$ => saga$
.filter(whenAction(REQUEST_PRODUCTS))
.mergeMap(() => shop.default.getProducts(300))
.map(res => {
return {
type: RECEIVED_PRODUCTS,
payload: res
};
});
示例5:
return iteration$ => iteration$
.filter(whenAction(REQUEST_ARTISTS))
.mergeMap(() => ArtistAPI.default.getArtists(300))
.map(res => {
return {
type: RECEIVED_ARTISTS,
payload: res
};
});
示例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))
)
);
示例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)
)
);
示例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
};
})
});
};