Skip to content

Commit

Permalink
* core: add this argument to fetcher callback.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Aug 31, 2024
1 parent e9c75cf commit 9998568
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/core/src/ajax/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {$} from '../cash';
import {Ajax} from './ajax';
import type {AjaxSetting, FetcherSetting} from './types';

export async function fetchData<T = {}, A extends unknown[] = unknown[]>(setting: FetcherSetting<T, A>, args: A = ([] as unknown as A), extraAjaxSetting?: Partial<AjaxSetting> | ((ajaxSetting: AjaxSetting) => Partial<AjaxSetting>)): Promise<T> {
export async function fetchData<T = {}, A extends unknown[] = unknown[], THIS = unknown>(setting: FetcherSetting<T, A, THIS>, args: A = ([] as unknown as A), extraAjaxSetting?: Partial<AjaxSetting> | ((ajaxSetting: AjaxSetting) => Partial<AjaxSetting>), thisObj?: THIS): Promise<T> {
const ajaxSetting = {throws: true, dataType: 'json'} as AjaxSetting;
if (typeof setting === 'string') {
ajaxSetting.url = formatString(setting, ...args);
} else if (typeof setting === 'object') {
$.extend(ajaxSetting, setting);
} else if (typeof setting === 'function') {
const result = setting(...args);
const result = setting.call(thisObj as THIS, ...args);
if (result instanceof Promise) {
const data = await result;
return data;
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/ajax/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ export type FetcherUrl = string;

export type FetcherInit = AjaxSetting;

export type FetcherFn<T = {}, A extends unknown[] = unknown[]> = (...args: A) => Promise<T> | T;
export type FetcherFn<T = {}, A extends unknown[] = unknown[], THIS = unknown> = (this: THIS, ...args: A) => Promise<T> | T;

export type FetcherSetting<T = {}, A extends unknown[] = unknown[]> = FetcherUrl | FetcherInit | FetcherFn<T, A>;
export type FetcherSetting<T = {}, A extends unknown[] = unknown[], THIS = unknown> = FetcherUrl | FetcherInit | FetcherFn<T, A, THIS>;

0 comments on commit 9998568

Please sign in to comment.