vue#DeepReadonly TypeScript Examples

The following examples show how to use vue#DeepReadonly. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: usePlocState.ts    From frontend-clean-architecture with MIT License 6 votes vote down vote up
export function usePlocState<S>(ploc: Ploc<S>): DeepReadonly<Ref<S>> {
    const state = ref(ploc.state) as Ref<S>;

    const stateSubscription = (newState: S) => {
        state.value = newState;
    };

    onMounted(() => {
        ploc.subscribe(stateSubscription);
    });

    onUnmounted(() => {
        ploc.unsubscribe(stateSubscription);
    });

    return readonly(state);
}
Example #2
Source File: use-state.ts    From fect with MIT License 5 votes vote down vote up
useState = <T>(initial?: T) => {
  const state = ref<T | undefined>(initial)
  const dispatch = (next: SetStateAction<T>) => {
    const draft = typeof next === 'function' ? (next as (prevState: T) => T)(state.value as T) : next
    state.value = draft as UnwrapRef<T>
  }
  return [readonly(state), dispatch] as [DeepReadonly<Ref<T>>, Dispatch<T>]
}
Example #3
Source File: useResize.test.ts    From vhook with MIT License 5 votes vote down vote up
width: DeepReadonly<Ref<number>>
Example #4
Source File: useResize.test.ts    From vhook with MIT License 5 votes vote down vote up
height: DeepReadonly<Ref<number>>
Example #5
Source File: useWindowScroll.test.ts    From vhook with MIT License 5 votes vote down vote up
x: DeepReadonly<Ref<number>>
Example #6
Source File: useWindowScroll.test.ts    From vhook with MIT License 5 votes vote down vote up
y: DeepReadonly<Ref<number>>