Skip to content

Commit 83de6bb

Browse files
authored
Improve comments (#238)
* docs: improve documentation * docs: improve documentation on pagination * remove readonly of total field
1 parent 46446d5 commit 83de6bb

File tree

6 files changed

+276
-61
lines changed

6 files changed

+276
-61
lines changed

docs/api/core.api.md

Lines changed: 72 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ export interface ArrayPaginationResult<T extends Array<any>>
1212
result: Readonly<Ref<T>>;
1313
}
1414

15-
// Warning: (ae-forgotten-export) The symbol "i18nDefinition" needs to be exported by the entry point index.d.ts
16-
// Warning: (ae-forgotten-export) The symbol "i18nResult" needs to be exported by the entry point index.d.ts
1715
// Warning: (ae-forgotten-export) The symbol "I18nExtractLocale" needs to be exported by the entry point index.d.ts
1816
//
19-
// @public (undocumented)
17+
// @public
2018
export function buildI18n<
2119
T extends i18nDefinition<TMessage>,
2220
TMessage extends Record<keyof T["messages"], i18n | (() => Promise<any>)>
@@ -68,11 +66,60 @@ export type FormatValue =
6866
| RefTyped<string>
6967
| RefTyped<number>;
7068

71-
// Warning: (ae-forgotten-export) The symbol "i18nMessageValue" needs to be exported by the entry point index.d.ts
72-
//
73-
// @public (undocumented)
69+
// @public
7470
export interface i18n extends Record<string, i18nMessageValue> {}
7571

72+
// @public
73+
export interface i18nDefinition<TMessage> {
74+
fallback?: keyof TMessage;
75+
locale: keyof TMessage;
76+
messages: {
77+
[K in keyof TMessage]: i18n | (() => Promise<i18n>) | (() => i18n);
78+
};
79+
notFoundFallback?: boolean;
80+
resolve?: i18nResolver;
81+
}
82+
83+
// @public
84+
export type i18nLocale<T> = {
85+
[K in keyof T]: i18nMessage<T[K]>;
86+
};
87+
88+
// @public
89+
export type i18nMessage<T> = T extends Ref<string>
90+
? string
91+
: T extends () => Promise<infer P>
92+
? i18nLocale<P>
93+
: T extends (...args: infer TArgs) => RefTyped<string>
94+
? (...args: TArgs) => string
95+
: T extends object
96+
? i18nLocale<T>
97+
: T extends Ref<infer V>
98+
? V
99+
: T;
100+
101+
// @public
102+
export type i18nMessageValue = i18nLocale<any> | RefTyped<string>;
103+
104+
// @public
105+
export type i18nResolver = (
106+
i18n: i18n,
107+
path: Readonly<RefTyped<string>>,
108+
args: RefTyped<FormatObject> | Array<FormatValue> | undefined
109+
) => RefTyped<string>;
110+
111+
// @public
112+
export interface i18nResult<TLocales, TMessages extends any = i18n> {
113+
$t(path: string, args?: object | Array<object>): Readonly<Ref<string>>;
114+
$ts(path: string, args?: object | Array<object>): string;
115+
// (undocumented)
116+
addLocale(locale: string, messages: TMessages): void;
117+
i18n: Readonly<Ref<Readonly<TMessages>>>;
118+
locale: Ref<TLocales>;
119+
locales: Readonly<Ref<Readonly<Array<TLocales>>>>;
120+
removeLocale(locale: TLocales): void;
121+
}
122+
76123
// @public (undocumented)
77124
export const isArray: (arg: any) => arg is any[];
78125

@@ -126,38 +173,27 @@ export type Options = {
126173
isImmediate: boolean;
127174
};
128175

129-
// @public (undocumented)
176+
// @public
177+
export type PaginationControl = () => void;
178+
179+
// @public
130180
export interface PaginationOptions {
131-
// (undocumented)
132181
currentPage: RefTyped<number>;
133-
// (undocumented)
134182
pageSize: RefTyped<number>;
135-
// (undocumented)
136183
total: RefTyped<number>;
137184
}
138185

139-
// @public (undocumented)
186+
// @public
140187
export interface PaginationResult {
141-
// (undocumented)
142188
currentPage: Ref<number>;
143-
// (undocumented)
144189
first: PaginationControl;
145-
// (undocumented)
146190
last: PaginationControl;
147-
// (undocumented)
148191
lastPage: Readonly<Ref<number>>;
149-
// Warning: (ae-forgotten-export) The symbol "PaginationControl" needs to be exported by the entry point index.d.ts
150-
//
151-
// (undocumented)
152192
next: PaginationControl;
153-
// (undocumented)
154193
offset: Ref<number>;
155-
// (undocumented)
156194
pageSize: Ref<number>;
157-
// (undocumented)
158195
prev: PaginationControl;
159-
// (undocumented)
160-
total: Ref<number>;
196+
total: Readonly<Ref<Readonly<number>>>;
161197
}
162198

163199
// @public (undocumented)
@@ -207,7 +243,7 @@ export interface RetryReturnNoFactory extends RetryReturn {
207243
exec<T>(fn: () => T): T;
208244
}
209245

210-
// @public (undocumented)
246+
// @public
211247
export function setI18n<
212248
T extends i18nDefinition<TMessage>,
213249
TMessage extends Record<keyof T["messages"], i18n | (() => Promise<any>)>
@@ -330,7 +366,7 @@ export function useDebounce<T extends Procedure>(
330366
options?: Options
331367
): T;
332368

333-
// @public (undocumented)
369+
// @public
334370
export function useFormat(
335371
format: RefTyped<Readonly<string>>,
336372
obj?: RefTyped<FormatObject>
@@ -342,7 +378,7 @@ export function useFormat(
342378
obj?: RefTyped<FormatObject>
343379
): Readonly<Ref<string>>;
344380

345-
// @public (undocumented)
381+
// @public
346382
export function useFormat(
347383
format: Readonly<RefTyped<string>>,
348384
...args: Array<FormatValue>
@@ -360,13 +396,13 @@ export function useFormat(
360396
args: any
361397
): Readonly<Ref<string>>;
362398

363-
// @public (undocumented)
399+
// @public
364400
export function useI18n<
365401
T extends i18nDefinition<TMessage>,
366402
TMessage extends Record<keyof T["messages"], i18n | (() => Promise<any>)>
367403
>(definition: T): i18nResult<keyof T["messages"], T["messages"][T["locale"]]>;
368404

369-
// @public (undocumented)
405+
// @public
370406
export function useI18n<T = i18n>(): i18nResult<string[], T>;
371407

372408
// @public
@@ -382,24 +418,24 @@ export interface UseNowOptions {
382418
timeFn?: () => number;
383419
}
384420

385-
// @public (undocumented)
421+
// @public
386422
export function usePagination(options: PaginationOptions): PaginationResult;
387423

388-
// @public (undocumented)
389-
export function usePath<T = any>(
390-
source: RefTyped<object>,
424+
// @public
425+
export function usePath<T = any, TSource = any>(
426+
source: RefTyped<TSource>,
391427
path: RefTyped<string>,
392428
separator?: string,
393-
notFoundReturn?: UsePathNotFoundReturn
429+
notFoundReturn?: UsePathNotFoundReturn<TSource>
394430
): Ref<Readonly<T>>;
395431

396432
// @public (undocumented)
397-
export type UsePathNotFoundReturn<T = any> = (
433+
export type UsePathNotFoundReturn<TSource> = (
398434
path: string,
399435
source: any,
400436
fullPath: string,
401-
originalSource: any
402-
) => T;
437+
originalSource: TSource
438+
) => any;
403439

404440
// @public
405441
export function usePerformanceNow(

examples/vue-composable-example/src/components/SharedRef.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
<script>
1616
import { useSharedRef } from "vue-composable";
17-
import { computed } from "@vue/composition-api";
17+
import { computed, defineComponent } from "@vue/composition-api";
1818
19-
export default {
19+
export default defineComponent({
2020
setup() {
2121
const s = useSharedRef("test", 0);
2222
@@ -39,5 +39,5 @@ export default {
3939
changeMind
4040
};
4141
}
42-
};
42+
});
4343
</script>

packages/core/src/format/format.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ export interface FormatObject {
99
[id: string]: FormatValue;
1010
}
1111

12+
/**
13+
* format string based on object: [format](https://pikax.me/vue-composable/composable/format/format)
14+
* * @example
15+
* ```ts
16+
* useFormat('Today is {{ day }}', { day: new Date().getDay() })
17+
* ```
18+
* @param format - string format
19+
* @param obj - object to get values from
20+
*/
1221
export function useFormat(
1322
format: RefTyped<Readonly<string>>,
1423
obj?: RefTyped<FormatObject>
@@ -19,6 +28,16 @@ export function useFormat(
1928
obj?: RefTyped<FormatObject>
2029
): Readonly<Ref<string>>;
2130

31+
/**
32+
* format string based on object: [format](https://pikax.me/vue-composable/composable/format/format)
33+
* * @example
34+
* ```ts
35+
* useFormat('Today is {{ 0 }}', new Date().getDay())
36+
* ```
37+
* @param format - string format
38+
* @param args - array based format
39+
*
40+
*/
2241
export function useFormat(
2342
format: Readonly<RefTyped<string>>,
2443
...args: Array<FormatValue>

packages/core/src/format/path.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
import { RefTyped, unwrap, isObject, NO_OP } from "../utils";
22
import { computed, Ref } from "@vue/composition-api";
33

4-
export type UsePathNotFoundReturn<T = any> = (
4+
export type UsePathNotFoundReturn<TSource> = (
5+
/**
6+
* Current path
7+
*/
58
path: string,
9+
/**
10+
* last source found
11+
*/
612
source: any,
13+
/**
14+
* Full path requested
15+
*/
716
fullPath: string,
8-
originalSource: any
9-
) => T;
17+
/**
18+
* Original source
19+
*/
20+
originalSource: TSource
21+
) => any;
1022

11-
export function usePath<T = any>(
12-
source: RefTyped<object>,
23+
/**
24+
* Retrieve object value based on string path
25+
* @param source - Source object to retrieve path
26+
* @param path - string path to value
27+
* @param separator - path separator, default '.'
28+
* @param notFoundReturn - not found handler
29+
*/
30+
export function usePath<T = any, TSource = any>(
31+
source: RefTyped<TSource>,
1332
path: RefTyped<string>,
1433
separator: string = ".",
15-
notFoundReturn: UsePathNotFoundReturn = NO_OP
34+
notFoundReturn: UsePathNotFoundReturn<TSource> = NO_OP
1635
): Ref<Readonly<T>> {
1736
return computed(() => {
1837
const s = unwrap(source);
@@ -25,7 +44,7 @@ export function usePath<T = any>(
2544
}
2645

2746
const fragments = p.split(separator);
28-
let c = s;
47+
let c: Record<string, any> = s;
2948
for (let i = 0; i < fragments.length; i++) {
3049
let fragmentPath = fragments[i];
3150

0 commit comments

Comments
 (0)