mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-03-06 15:55:25 +00:00
client - refactor services
This commit is contained in:
@@ -2,17 +2,18 @@ import { cloneDeep } from 'lodash';
|
||||
import axios from '../axios/axios';
|
||||
import { CategoryModel } from '../model';
|
||||
|
||||
export class CategoryService {
|
||||
private static categoryCache: CategoryModel[];
|
||||
|
||||
public static async getCategories(): Promise<CategoryModel[]> {
|
||||
// return cache if it exists
|
||||
if (CategoryService.categoryCache) {
|
||||
return Promise.resolve(cloneDeep(CategoryService.categoryCache));
|
||||
}
|
||||
|
||||
const res = await axios.get('/api/category');
|
||||
CategoryService.categoryCache = cloneDeep(res.data.data);
|
||||
return res.data.data;
|
||||
let categoryCache: CategoryModel[];
|
||||
const getCategories = async () => {
|
||||
// return cache if it exists
|
||||
if (categoryCache) {
|
||||
return Promise.resolve(cloneDeep(categoryCache));
|
||||
}
|
||||
|
||||
const res = await axios.get('/api/category');
|
||||
categoryCache = cloneDeep(res.data.data);
|
||||
return res.data.data;
|
||||
}
|
||||
|
||||
export const CategoryService = {
|
||||
getCategories,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user