Skip to content

Commit

Permalink
Merge pull request #27 from xiachufang/dev
Browse files Browse the repository at this point in the history
feat: 几个类型补全和useFetchQueueHelper增加run函数
  • Loading branch information
zanllp authored Jun 23, 2022
2 parents bf0cd1f + ff7cda4 commit bf04cf3
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue3-ts-util",
"version": "0.3.34",
"version": "0.3.35",
"main": "dist/index.js",
"module": "es/src/index.js",
"types": "es/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions src/GeneralPagination/index.vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
declare const _default: import("vue").DefineComponent<{
option: {
type: import("vue").PropType<{
type: import("vue").PropType<import("..").DeepReadonly<{
onChange: (page: number) => Promise<void>;
total: number;
pageSize: number;
curr: number;
setCurr: (v: number) => void;
}>;
}>>;
required: true;
};
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{
option?: unknown;
} & {
option: {
option: import("..").DeepReadonly<{
onChange: (page: number) => Promise<void>;
total: number;
pageSize: number;
curr: number;
setCurr: (v: number) => void;
};
}>;
} & {}>, {}>;
/**
* @example
Expand Down
7 changes: 6 additions & 1 deletion src/SearchSelect/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:options="currOptions"
optionLabelProp="title"
show-search
:mode="mode"
v-bind="$attrs"
/>
</template>
Expand All @@ -28,7 +29,11 @@ export default defineComponent({
/**
* 配置如何将选项转换成显示的文本,值,键
*/
conv: customPropType<SearchSelectConv<any>>()
conv: customPropType<SearchSelectConv<any>>(),
/**
* 需要多选加上这个
*/
mode: customPropType<'multiple'>(false)
},
setup (props, ctx) {
const searchTarget = ref('') // 当前搜索目标
Expand Down
11 changes: 10 additions & 1 deletion src/SearchSelect/index.vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ declare const _default: import("vue").DefineComponent<{
type: import("vue").PropType<SearchSelectConv<any>>;
required: true;
};
/**
* 需要多选加上这个
*/
mode: {
type: import("vue").PropType<"multiple">;
};
}, {
currOptions: import("vue").ComputedRef<any>;
onSearch: (target: string) => void;
Expand All @@ -27,9 +33,12 @@ declare const _default: import("vue").DefineComponent<{
value?: unknown;
options?: unknown;
conv?: unknown;
mode?: unknown;
} & {
value: unknown;
options: any[];
conv: SearchSelectConv<any>;
} & {}>, {}>;
} & {
mode?: "multiple" | undefined;
}>, {}>;
export default _default;
15 changes: 8 additions & 7 deletions src/SplitView/index.vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
declare const _default: import("vue").DefineComponent<{
percent: {
type: import("vue").PropType<number>;
required: true;
default: number;
};
border: {
type: import("vue").PropType<boolean>;
required: true;
default: boolean;
};
direction: {
type: import("vue").PropType<"vertical" | "horizontal">;
required: true;
default: "vertical" | "horizontal";
};
}, {
split: Readonly<import("vue").Ref<{
Expand All @@ -26,5 +23,9 @@ declare const _default: import("vue").DefineComponent<{
percent: number;
border: boolean;
direction: "vertical" | "horizontal";
} & {}>, {}>;
} & {}>, {
percent: number;
border: boolean;
direction: "vertical" | "horizontal";
}>;
export default _default;
1 change: 1 addition & 0 deletions src/fetchQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,5 @@ export class FetchQueue {
this.tryRunNext() // 尝试运行刚才压入的任务
return deepReadonly(task)
}

}
5 changes: 1 addition & 4 deletions src/strictQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import { FetchQueue, useFetchQueueHelper } from '.'
*/
export const strictQueue = (args: ConstructorParameters<typeof FetchQueue> = [1, 0, -1, 'throw']) => {
const fetchQueue = new FetchQueue(...args)
return useFetchQueueHelper(fetchQueue) as {
loading: ComputedRef<boolean>
fetchQueue: FetchQueue
} // 编译时好像有点问题手动指定
return useFetchQueueHelper(fetchQueue)
}
export const useStrictQueue = strictQueue
3 changes: 3 additions & 0 deletions src/useFetchQueueHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export const useFetchQueueHelper = (fetchQueue: FetchQueue) => {
})
return {
fetchQueue,
async run<R> (action: () => Promise<R>): Promise<R> {
return fetchQueue.pushAction(action).res
},
...deepReadonly({
loading,
})
Expand Down
17 changes: 17 additions & 0 deletions test/FetchQueue/hook.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable no-plusplus */
import { delay, useStrictQueue } from '../../src'

describe('useFetchQueueHelper', () => {

it('套层皮的简单综合测试', async () => {
const { run, loading } = useStrictQueue()
expect(loading.value).toBe(false)
const r = run(async () => {
await delay(100)
return 1
})
expect(loading.value).toBe(true)
expect(await r).toBe(1)
expect(loading.value).toBe(false)
})
})

0 comments on commit bf04cf3

Please sign in to comment.