feature: Create BaseFontStore class with Tanstack query logic and FontshareStore, GoogleFontsStore based on it
This commit is contained in:
27
src/entities/Font/model/store/googleFontsStore.svelte.ts
Normal file
27
src/entities/Font/model/store/googleFontsStore.svelte.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { GoogleFontsParams } from '../../api';
|
||||
import { fetchGoogleFontsQuery } from '../services';
|
||||
import type { UnifiedFont } from '../types';
|
||||
import { BaseFontStore } from './baseFontStore.svelte';
|
||||
|
||||
/**
|
||||
* Google Fonts store wrapping TanStack Query with runes
|
||||
*/
|
||||
export class GoogleFontsStore extends BaseFontStore<GoogleFontsParams> {
|
||||
constructor(initialParams: GoogleFontsParams = {}) {
|
||||
super(initialParams);
|
||||
}
|
||||
|
||||
protected getQueryKey(params: GoogleFontsParams) {
|
||||
return ['googleFonts', params] as const;
|
||||
}
|
||||
|
||||
protected async fetchFn(params: GoogleFontsParams): Promise<UnifiedFont[]> {
|
||||
return fetchGoogleFontsQuery(params);
|
||||
}
|
||||
}
|
||||
|
||||
export function createFontshareStore(params: GoogleFontsParams = {}) {
|
||||
return new GoogleFontsStore(params);
|
||||
}
|
||||
|
||||
export const googleFontsStore = new GoogleFontsStore();
|
||||
Reference in New Issue
Block a user