Skip to content

Commit 936dd68

Browse files
committed
chore: NIP
1 parent 4a4561c commit 936dd68

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

dev/Readonly.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ export const Component: React.FC = () => {
1717
<div>
1818
<mark>renderCount: {renderCount}</mark>
1919
<pre>shallowReadonlyObject = {JSON.stringify(shallowReadonlyObject, null, 2)}</pre>
20+
{/* @ts-ignore */}
2021
<button onClick={() => shallowReadonlyObject.data++}>shallowReadonlyObject.data++</button>
2122
<button onClick={() => shallowReadonlyObject.nested.data++}>shallowReadonlyObject.nested.data++</button>
2223
<hr />
2324
<pre>readonlyObject = {JSON.stringify(readonlyObject, null, 2)}</pre>
25+
{/* @ts-ignore */}
2426
<button onClick={() => readonlyObject.data++}>readonlyObject.data++</button>
27+
{/* @ts-ignore */}
2528
<button onClick={() => readonlyObject.nested.data++}>readonlyObject.nested.data++</button>
2629
</div>
2730
)

src/computed.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
*/
55

66
import { useState as useReactState } from 'react'
7-
import { useWatch } from './watch'
8-
import { useForceUpdate } from './_utils'
9-
import { computed as vComputed } from '@vue/reactivity'
7+
import { computed as vueComputed } from '@vue/reactivity'
108
import type {
11-
ComputedGetter,
12-
DebuggerOptions,
139
ComputedRef,
14-
WritableComputedOptions,
10+
ComputedGetter,
1511
WritableComputedRef,
12+
WritableComputedOptions,
13+
DebuggerOptions,
1614
} from '@vue/reactivity'
15+
import { useWatch } from './watch'
16+
import { useForceUpdate } from './_utils'
1717

1818
/**
1919
* Takes a getter function and returns a readonly reactive ref object for the
@@ -55,7 +55,7 @@ export function useComputed<T, S = T>(
5555
debugOptions?: DebuggerOptions,
5656
): WritableComputedRef<T, S>
5757
export function useComputed(arg1: any, arg2: any) {
58-
const [value] = useReactState(() => vComputed(arg1, arg2))
58+
const [value] = useReactState(() => vueComputed(arg1, arg2))
5959
const forceUpdate = useForceUpdate()
6060
useWatch(value, forceUpdate)
6161
return value

src/effectScope.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { useState as useReactState, useRef as useReactRef, useCallback as useReactCallback } from 'react'
7-
import { effectScope } from '@vue/reactivity'
7+
import { effectScope as vueEffectScope } from '@vue/reactivity'
88
import { ArgumentTypes } from './_utils'
99

1010
/**
@@ -16,9 +16,9 @@ import { ArgumentTypes } from './_utils'
1616
* @param detached - Can be used to create a "detached" effect scope.
1717
* @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope Vue `effectScope()`}
1818
*/
19-
export function useEffectScope(...args: ArgumentTypes<typeof effectScope>) {
19+
export function useEffectScope(...args: ArgumentTypes<typeof vueEffectScope>) {
2020
const hasRun = useReactRef(false)
21-
const [scope] = useReactState(() => effectScope(...args))
21+
const [scope] = useReactState(() => vueEffectScope(...args))
2222
const originalRunRef = useReactRef(scope.run)
2323
const runFn = useReactCallback(<T>(fn: () => T) => {
2424
if (!hasRun.current) {

src/reactive.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*/
55

66
import { useState as useReactState } from 'react'
7+
import { reactive as vueReactive, shallowReactive as vueShallowReactive } from '@vue/reactivity'
8+
import type { Reactive, ShallowReactive } from '@vue/reactivity'
79
import { useWatch } from './watch'
810
import { useForceUpdate } from './_utils'
9-
import { reactive as vReactive, shallowReactive as vShallowReactive } from '@vue/reactivity'
10-
import type { Reactive, ShallowReactive } from '@vue/reactivity'
1111

1212
/**
1313
* Returns a reactive proxy of the object.
@@ -26,7 +26,7 @@ import type { Reactive, ShallowReactive } from '@vue/reactivity'
2626
*/
2727
export function useReactive<T extends object>(target: T): Reactive<T>
2828
export function useReactive(target: object) {
29-
const [value] = useReactState(() => vReactive(target))
29+
const [value] = useReactState(() => vueReactive(target))
3030
const forceUpdate = useForceUpdate()
3131
useWatch(value, forceUpdate)
3232
return value
@@ -63,7 +63,7 @@ export function useReactive(target: object) {
6363
* ```
6464
*/
6565
export function useShallowReactive<T extends object>(target: T): ShallowReactive<T> {
66-
const [value] = useReactState(() => vShallowReactive(target))
66+
const [value] = useReactState(() => vueShallowReactive(target))
6767
const forceUpdate = useForceUpdate()
6868
useWatch(value, forceUpdate)
6969
return value

src/readonly.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*/
55

66
import { useState as useReactState } from 'react'
7+
import { readonly as vueReadonly, shallowReadonly as vueShallowReadonly } from '@vue/reactivity'
8+
import type { DeepReadonly, UnwrapNestedRefs } from '@vue/reactivity'
79
import { useWatch } from './watch'
810
import { useForceUpdate } from './_utils'
9-
import { readonly as vReadonly, shallowReadonly as vShallowReadonly } from '@vue/reactivity'
10-
import type { DeepReadonly, UnwrapNestedRefs } from '@vue/reactivity'
1111

1212
/**
1313
* Takes an object (reactive or plain) or a ref and returns a readonly proxy to
@@ -38,7 +38,7 @@ import type { DeepReadonly, UnwrapNestedRefs } from '@vue/reactivity'
3838
* ```
3939
*/
4040
export function useReadonly<T extends object>(target: T): DeepReadonly<UnwrapNestedRefs<T>> {
41-
const [value] = useReactState(() => vReadonly(target))
41+
const [value] = useReactState(() => vueReadonly(target))
4242
const forceUpdate = useForceUpdate()
4343
useWatch(value, forceUpdate)
4444
return value
@@ -78,7 +78,7 @@ export function useReadonly<T extends object>(target: T): DeepReadonly<UnwrapNes
7878
* ```
7979
*/
8080
export function useShallowReadonly<T extends object>(target: T): Readonly<T> {
81-
const [value] = useReactState(() => vShallowReadonly(target))
81+
const [value] = useReactState(() => vueShallowReadonly(target))
8282
const forceUpdate = useForceUpdate()
8383
useWatch(value, forceUpdate)
8484
return value

src/ref.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*/
55

66
import { useState as useReactState } from 'react'
7+
import { ref as vueRef, shallowRef as vueShallowRef, customRef as vueCustomRef } from '@vue/reactivity'
8+
import type { Ref, UnwrapRef, ShallowRef, CustomRefFactory } from '@vue/reactivity'
79
import { useForceUpdate, IfAny } from './_utils'
810
import { useWatch } from './watch'
9-
import { ref as vRef, shallowRef as vShallowRef, customRef as vCustomRef } from '@vue/reactivity'
10-
import type { Ref, UnwrapRef, ShallowRef, CustomRefFactory } from '@vue/reactivity'
1111

1212
/**
1313
* Takes an inner value and returns a reactive and mutable ref object, which
@@ -30,10 +30,10 @@ export function useRef<T>(
3030
): [T] extends [Ref] ? IfAny<T, Ref<T>, T> : Ref<UnwrapRef<T>, UnwrapRef<T> | T>
3131
export function useRef<T = any>(): Ref<T | undefined>
3232
export function useRef(initValue?: unknown) {
33-
const [refObj] = useReactState(() => vRef(initValue))
33+
const [refObject] = useReactState(() => vueRef(initValue))
3434
const forceUpdate = useForceUpdate()
35-
useWatch(refObj, forceUpdate, { deep: true })
36-
return refObj as unknown as any
35+
useWatch(refObject, forceUpdate, { deep: true })
36+
return refObject as unknown as any
3737
}
3838

3939
/**
@@ -56,10 +56,10 @@ export function useShallowRef<T>(
5656
): Ref extends T ? (T extends Ref ? IfAny<T, ShallowRef<T>, T> : ShallowRef<T>) : ShallowRef<T>
5757
export function useShallowRef<T = any>(): ShallowRef<T | undefined>
5858
export function useShallowRef(initValue?: unknown) {
59-
const [sRefObj] = useReactState(() => vShallowRef(initValue))
59+
const [shallowRefObject] = useReactState(() => vueShallowRef(initValue))
6060
const forceUpdate = useForceUpdate()
61-
useWatch(sRefObj, forceUpdate)
62-
return sRefObj
61+
useWatch(shallowRefObject, forceUpdate)
62+
return shallowRefObject
6363
}
6464

6565
/**
@@ -70,8 +70,8 @@ export function useShallowRef(initValue?: unknown) {
7070
* @see {@link https://vuejs.org/api/reactivity-advanced.html#customref Vue `customRef()`}
7171
*/
7272
export function useCustomRef<T>(factory: CustomRefFactory<T>): Ref<T> {
73-
const [cRefObj] = useReactState(() => vCustomRef(factory))
73+
const [customRefObject] = useReactState(() => vueCustomRef(factory))
7474
const forceUpdate = useForceUpdate()
75-
useWatch(cRefObj, forceUpdate)
76-
return cRefObj
75+
useWatch(customRefObject, forceUpdate)
76+
return customRefObject
7777
}

0 commit comments

Comments
 (0)