本文整理汇总了TypeScript中domain-task/fetch.fetch函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fetch函数的具体用法?TypeScript fetch怎么用?TypeScript fetch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fetch函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: fetch
requestGenresList: (): ActionCreator => (dispatch, getState) => {
if (!getState().genreList.isLoaded) {
fetch('/api/genres')
.then(results => results.json())
.then(genres => dispatch(new ReceiveGenresList(genres)));
}
}
示例2: fetch
userList: (): ActionCreator => (dispatch, getState) => {
fetch(`/users`,{ method: 'GET'})
.then(response => response.json())
.then((data: any) => {
dispatch(new UserList(data.data));
});
dispatch(new UserLoad());
},
示例3: fetch
requestFeaturedAlbums: (): ActionCreator => (dispatch, getState) => {
if (!getState().featuredAlbums.isLoaded) {
fetch('/api/albums/mostPopular')
.then(results => results.json())
.then(albums => dispatch(new ReceiveFeaturedAlbums(albums)));
return dispatch(new RequestFeaturedAlbums());
}
}
示例4: getState
vote: (pollId: number, choiceId: number): ActionCreator => (dispatch, getState) => {
let bearer = getState().auth.token;
fetch(`/api/polls/${pollId}/choices/${choiceId}`, {
method: 'post',
headers: {
'Authorization': `Bearer ${bearer}`,
}
});
}
示例5: dispatch
userItem: (UUID,callback): ActionCreator => (dispatch, getState) => {
dispatch(new UserItem(UserModel.Model));
fetch(`/users/`+UUID,{ method: 'GET'})
.then(response => response.json())
.then((data: any) => {
dispatch(new UserItem(data.data));
callback();
});
dispatch(new UserLoad());
},
示例6: fetch
requestWeatherForecasts: (startDateIndex: number): ActionCreator => (dispatch, getState) => {
// Only load data if it's something we don't already have (and are not already loading)
if (startDateIndex !== getState().weatherForecasts.startDateIndex) {
fetch(`/api/SampleData/WeatherForecasts?startDateIndex=${ startDateIndex }`)
.then(response => response.json())
.then((data: WeatherForecast[]) => {
dispatch(new ReceiveWeatherForecasts(startDateIndex, data));
});
dispatch(new RequestWeatherForecasts(startDateIndex));
}
}
示例7: fetch
requestAlbumDetails: (albumId: number): ActionCreator => (dispatch, getState) => {
// Only load if it's not already loaded (or currently being loaded)
if (albumId !== getState().albumDetails.requestedAlbumId) {
fetch(`/api/albums/${ albumId }`)
.then(results => results.json())
.then(album => {
// Only replace state if it's still the most recent request
if (albumId === getState().albumDetails.requestedAlbumId) {
dispatch(new ReceiveAlbumDetails(album));
}
});
dispatch(new RequestAlbumDetails(albumId));
}
}