1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 10:54:44 +00:00

chore(packages/vue): update jsdoc, fill package.json

This commit is contained in:
2024-10-23 07:48:40 +07:00
parent b6d5b5b92c
commit c350c977d5
19 changed files with 66 additions and 6 deletions

View File

@@ -1,10 +1,15 @@
{
"name": "@robonen/vue",
"private": true,
"version": "0.0.0",
"license": "UNLICENSED",
"description": "",
"keywords": [],
"version": "0.0.1",
"license": "Apache-2.0",
"description": "Collection of powerful tools for Vue",
"keywords": [
"vue",
"tools",
"ui",
"utilities",
"composables"
],
"author": "Robonen Andrew <robonenandrew@gmail.com>",
"repository": {
"type": "git",

View File

@@ -25,6 +25,8 @@ export interface TryOnBeforeMountOptions {
*
* @example
* tryOnBeforeMount(() => console.log('Before mount async'), { sync: false });
*
* @since 0.0.1
*/
export function tryOnBeforeMount(fn: VoidFunction, options: TryOnBeforeMountOptions = {}) {
const {

View File

@@ -25,6 +25,8 @@ export interface TryOnMountedOptions {
*
* @example
* tryOnMounted(() => console.log('Mounted!'), { sync: false });
*
* @since 0.0.1
*/
export function tryOnMounted(fn: VoidFunction, options: TryOnMountedOptions = {}) {
const {

View File

@@ -14,6 +14,7 @@ const ComponentStub = defineComponent({
setup(props) {
tryOnScopeDispose(props.callback);
},
template: '<div></div>',
});
describe('tryOnScopeDispose', () => {

View File

@@ -11,6 +11,8 @@ import { getCurrentScope, onScopeDispose } from 'vue';
*
* @example
* tryOnScopeDispose(() => console.log('Scope disposed'));
*
* @since 0.0.1
*/
export function tryOnScopeDispose(callback: VoidFunction) {
if (getCurrentScope()) {

View File

@@ -23,6 +23,8 @@ import { effectScope } from 'vue';
* const increment = () => state.count++;
* return { state, increment };
* });
*
* @since 0.0.1
*/
export function useAppSharedState<Fn extends AnyFunction>(stateFactory: Fn) {
let initialized = false;

View File

@@ -19,6 +19,8 @@ export type Comparator<Value> = (a: Value, b: Value) => boolean;
* @example
* const externalValue = ref(0);
* const cachedValue = useCached(externalValue, (a, b) => a === b, { immediate: true });
*
* @since 0.0.1
*/
export function useCached<Value = unknown>(
externalValue: MaybeRefOrGetter<Value>,

View File

@@ -18,6 +18,8 @@ import { computed, isReadonly, ref, toValue, type ComputedRef, type MaybeRef, ty
* @example
* const value = ref(10);
* const clampedValue = useClamp(value, () => 0, () => 5);
*
* @since 0.0.1
*/
export function useClamp(value: MaybeRef<number>, min: MaybeRefOrGetter<number>, max: MaybeRefOrGetter<number>): WritableComputedRef<number>;
export function useClamp(value: MaybeRefOrGetter<number>, min: MaybeRefOrGetter<number>, max: MaybeRefOrGetter<number>): ComputedRef<number> {

View File

@@ -12,6 +12,8 @@ import { VueToolsError } from '../..';
*
* @example
* const [injectContext, provideContext] = useContextFactory('MyContext');
*
* @since 0.0.1
*/
export function useContextFactory<ContextValue>(name: string) {
const injectionKey: InjectionKey<ContextValue> = Symbol(name);

View File

@@ -31,6 +31,8 @@ export interface UseConterReturn {
*
* @example
* const { count, increment, decrement, set, get, reset } = useCounter(0, { min: 0, max: 10 });
*
* @since 0.0.1
*/
export function useCounter(
initialValue: MaybeRefOrGetter<number> = 0,

View File

@@ -24,6 +24,8 @@ export interface UseLastChangedOptions<
* @example
* const value = ref(0);
* const lastChanged = useLastChanged(value, { immediate: true });
*
* @since 0.0.1
*/
export function useLastChanged(source: WatchSource, options?: UseLastChangedOptions<false>): Ref<number | null>;
export function useLastChanged(source: WatchSource, options: UseLastChangedOptions<true> | UseLastChangedOptions<boolean, number>): Ref<number>

View File

@@ -14,6 +14,8 @@ import { getLifeCycleTarger } from '../..';
*
* @example
* const isMounted = useMounted(getCurrentInstance());
*
* @since 0.0.1
*/
export function useMounted(instance?: ComponentInternalInstance) {
const isMounted = ref(false);

View File

@@ -63,6 +63,8 @@ export type UseOffsetPaginationInfinityReturn = Omit<UseOffsetPaginationReturn,
* onPageSizeChange: ({ currentPageSize }) => console.log(currentPageSize),
* onTotalPagesChange: ({ totalPages }) => console.log(totalPages),
* });
*
* @since 0.0.1
*/
export function useOffsetPagination(options: Omit<UseOffsetPaginationOptions, 'total'>): UseOffsetPaginationInfinityReturn;
export function useOffsetPagination(options: UseOffsetPaginationOptions): UseOffsetPaginationReturn;

View File

@@ -15,6 +15,8 @@ import { getLifeCycleTarger } from '../..';
*
* @example
* const count = useRenderCount(getCurrentInstance());
*
* @since 0.0.1
*/
export function useRenderCount(instance?: ComponentInternalInstance) {
const { count, increment } = useCounter(0);

View File

@@ -1,3 +1,4 @@
import { timestamp } from '@robonen/stdlib';
import { onBeforeMount, onBeforeUpdate, onMounted, onUpdated, readonly, ref, type ComponentInternalInstance } from 'vue';
import { useRenderCount } from '../useRenderCount';
import { getLifeCycleTarger } from '../..';
@@ -15,6 +16,8 @@ import { getLifeCycleTarger } from '../..';
*
* @example
* const { component, count, duration, lastRendered } = useRenderInfo(getCurrentInstance());
*
* @since 0.0.1
*/
export function useRenderInfo(instance?: ComponentInternalInstance) {
const target = getLifeCycleTarger(instance);
@@ -33,6 +36,6 @@ export function useRenderInfo(instance?: ComponentInternalInstance) {
component: target?.type.name ?? target?.uid,
count: useRenderCount(instance),
duration: readonly(duration),
lastRendered: Date.now(),
lastRendered: timestamp(),
};
}

View File

@@ -14,6 +14,8 @@ import { useMounted } from '../useMounted';
*
* @example
* const isSupported = useSupported(() => 'ResizeObserver' in window);
*
* @since 0.0.1
*/
export function useSupported(feature: () => unknown) {
const isMounted = useMounted();

View File

@@ -21,6 +21,8 @@ import { isArray } from '@robonen/stdlib';
* const source = ref(0);
* const target1 = ref(0);
* useSyncRefs(source, target1, { immediate: true });
*
* @since 0.0.1
*/
export function useSyncRefs<T = unknown>(
source: WatchSource<T>,

View File

@@ -1,5 +1,21 @@
import { getCurrentInstance, type ComponentInternalInstance } from 'vue';
/**
* @name getLifeCycleTarger
* @category Utils
* @description Function to get the target instance of the lifecycle hook
*
* @param {ComponentInternalInstance} target The target instance of the lifecycle hook
* @returns {ComponentInternalInstance | null} Instance of the lifecycle hook or null
*
* @example
* const target = getLifeCycleTarger();
*
* @example
* const target = getLifeCycleTarger(instance);
*
* @since 0.0.1
*/
export function getLifeCycleTarger(target?: ComponentInternalInstance) {
return target || getCurrentInstance();
}

View File

@@ -1,3 +1,10 @@
/**
* @name VueToolsError
* @category Error
* @description VueToolsError is a custom error class that represents an error in Vue Tools
*
* @since 0.0.1
*/
export class VueToolsError extends Error {
constructor(message: string) {
super(message);