Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add alova preset #369

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions src/presets/alova.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { defineUnimportPreset } from '../utils'

export const alovaCore = defineUnimportPreset({
from: 'alova',
imports: [
'createAlova',
'globalConfig',
'Method',

// cache actions
'queryCache',
'setCache',
'invalidateCache',
'hitCacheBySource',
],
})

export const alovaClient = defineUnimportPreset({
from: 'alova/client',
imports: [
// core hooks
'useRequest',
'useWatcher',
'useFetcher',

// scenario hooks
'usePagination',
'useSQRequest',
'useForm',
'useAutoRequest',
'useCaptcha',
'useRetriableRequest',
'useSSE',
'useSerialRequest',
'useSerialWatcher',

// interceptors
'createClientTokenAuthentication',
'createServerTokenAuthentication',

// middlewares
'actionDelegationMiddleware',
'accessAction',

// silent queue related
'bootSilentFactory',
'onBeforeSilentSubmit',
'onSilentSubmitBoot',
'onSilentSubmitError',
'onSilentSubmitFail',
'onSilentSubmitSuccess',
'silentQueueMap',
'dehydrateVData',
'equals',
'filterSilentMethods',
'getSilentMethod',
'isVData',
'stringifyVData',
'updateStateEffect',

// others
'updateState',
],
})

export const alovaServer = defineUnimportPreset({
from: 'alova/server',
imports: ['HookedMethod', 'createRateLimiter', 'retry'],
})

export const statesHookVue = defineUnimportPreset({
from: 'alova/vue',
imports: [
['default', 'statesHookVue'],
],
})

export const statesHookReact = defineUnimportPreset({
from: 'alova/react',
imports: [
['default', 'statesHookReact'],
],
})

export const statesHookSvelte = defineUnimportPreset({
from: 'alova/svelte',
imports: [
['default', 'statesHookSvelte'],
],
})

export const adapterFetch = defineUnimportPreset({
from: 'alova/fetch',
imports: [
['default', 'adapterFetch'],
],
})
16 changes: 16 additions & 0 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ import solidAppRouter from './solid-app-router'
import vueRouterComposables from './vue-router-composables'
import rxjs from './rxjs'
import dateFns from './date-fns'
import {
adapterFetch,
alovaClient,
alovaCore,
alovaServer,
statesHookReact,
statesHookSvelte,
statesHookVue,
} from './alova'

export const builtinPresets = {
'@vue/composition-api': vueCompositionApi,
Expand Down Expand Up @@ -62,6 +71,13 @@ export const builtinPresets = {
'solid-app-router': solidAppRouter,
'rxjs': rxjs,
'date-fns': dateFns,
'alova': alovaCore,
'alova/client': alovaClient,
'alova/server': alovaServer,
'alova/vue': statesHookVue,
'alova/react': statesHookReact,
'alova/svelte': statesHookSvelte,
'alova/fetch': adapterFetch,
}

export type BuiltinPresetName = keyof typeof builtinPresets