Skip to content

Commit 94b0e9c

Browse files
authored
Merge pull request #7 from veactjs/dev
v1.0.0
2 parents 6f6151a + d867e84 commit 94b0e9c

24 files changed

+610
-1298
lines changed

.vscode/settings.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
2+
"typescript.tsdk": "node_modules/typescript/lib",
23
"editor.defaultFormatter": "esbenp.prettier-vscode",
3-
"editor.detectIndentation": false,
4-
"editor.formatOnSave": true,
5-
"editor.formatOnType": true,
6-
"editor.codeActionsOnSave": {
7-
"source.fixAll": "explicit"
8-
},
9-
"typescript.tsdk": "node_modules/typescript/lib"
4+
"editor.formatOnSave": true
105
}

dev/Readonly.tsx

Lines changed: 3 additions & 0 deletions
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
)

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "veact",
3-
"version": "1.0.0-beta.2",
3+
"version": "1.0.0",
44
"description": "Mutable state enhancer library for React by @vue/reactivity",
55
"keywords": [
66
"React",
@@ -50,7 +50,7 @@
5050
"react-dom": "^16.8.0 || ^17 || ^18 || ^19"
5151
},
5252
"dependencies": {
53-
"@vue/reactivity": "^3.5.0-beta.2"
53+
"@vue/reactivity": ">=3.5"
5454
},
5555
"devDependencies": {
5656
"@eslint/js": "^9.x",
@@ -64,14 +64,14 @@
6464
"eslint-config-prettier": "^9.x",
6565
"eslint-plugin-prettier": "^5.x",
6666
"globals": "^15.9.0",
67-
"jsdom": "^24.x",
67+
"happy-dom": "^15.x",
6868
"prettier": "^3.x",
6969
"react": "^18.x",
7070
"react-dom": "^18.x",
7171
"typescript": "^5.5.4",
7272
"typescript-eslint": "^8.x",
7373
"vite": "^5.x",
74-
"vite-plugin-dts": "^4.0.3",
74+
"vite-plugin-dts": "^4.1.0",
7575
"vitest": "^2.x"
7676
}
7777
}

pnpm-lock.yaml

Lines changed: 335 additions & 683 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/_utils.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,3 @@ export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
1010

1111
export const increment = (s: number) => s + 1
1212
export const useForceUpdate = () => useReducer(increment, 0)[1]
13-
14-
// compare whether a value has changed, accounting for NaN.
15-
export const hasChanged = (value: any, oldValue: any): boolean => {
16-
return value !== oldValue && (value === value || oldValue === oldValue)
17-
}
18-
19-
export const isArray = Array.isArray
20-
export const objectToString = Object.prototype.toString
21-
export const toTypeString = (value: unknown): string => {
22-
return objectToString.call(value)
23-
}
24-
export const isMap = (value: unknown): value is Map<any, any> => {
25-
return toTypeString(value) === '[object Map]'
26-
}
27-
export const isSet = (value: unknown): value is Set<any> => {
28-
return toTypeString(value) === '[object Set]'
29-
}
30-
export const isDate = (value: unknown): value is Date => {
31-
return value instanceof Date
32-
}
33-
export const isFunction = (value: unknown): value is (...args: any[]) => any => {
34-
return typeof value === 'function'
35-
}
36-
export const isString = (value: unknown): value is string => {
37-
return typeof value === 'string'
38-
}
39-
export const isSymbol = (value: unknown): value is symbol => {
40-
return typeof value === 'symbol'
41-
}
42-
export const isObject = (value: unknown): value is Record<any, any> => {
43-
return value !== null && typeof value === 'object'
44-
}
45-
export const isPlainObject = (value: unknown): value is object => {
46-
return toTypeString(value) === '[object Object]'
47-
}
48-
export const isPromise = <T = any>(value: unknown): value is Promise<T> => {
49-
return isObject(value) && isFunction(value.then) && isFunction(value.catch)
50-
}
51-
52-
export const removeArrayItem = <T>(array: T[], element: T) => {
53-
const i = array.indexOf(element)
54-
if (i > -1) {
55-
array.splice(i, 1)
56-
}
57-
}

src/computed.ts

Lines changed: 7 additions & 7 deletions
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/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

Lines changed: 3 additions & 3 deletions
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/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
// redirect all APIs from @vue/reactivity
77
export * from '@vue/reactivity'
8+
export { watch as baseWatch } from '@vue/reactivity'
89

910
// lifecycle hooks
1011
export { onMounted, onUpdated, onBeforeUnmount } from './lifecycle'
@@ -22,15 +23,12 @@ export { useReadonly, useShallowReadonly } from './readonly'
2223
export { useComputed } from './computed'
2324

2425
// watch and hooks
25-
export { watch, useWatch } from './watch/watch'
26-
export type { WatchOptions, WatchSource, MultiWatchSources, WatchCallback } from './watch/watch'
26+
export { watch, useWatch } from './watch'
27+
export type { WatchOptions, MultiWatchSources } from './watch'
2728

2829
// watchEffect and hooks
29-
export { watchEffect, useWatchEffect } from './watch/watchEffect'
30-
export type { WatchEffect, WatchEffectOptions } from './watch/watchEffect'
31-
32-
// watch handle
33-
export type { WatchStopHandle, WatchHandle } from './watch/type'
30+
export { watchEffect, useWatchEffect } from './watchEffect'
31+
export type { WatchEffectOptions } from './watchEffect'
3432

3533
// effectScope hooks
3634
export { useEffectScope } from './effectScope'

src/reactive.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*/
55

66
import { useState as useReactState } from 'react'
7-
import { useWatch } from './watch/watch'
8-
import { useForceUpdate } from './_utils'
9-
import { reactive as vReactive, shallowReactive as vShallowReactive } from '@vue/reactivity'
7+
import { reactive as vueReactive, shallowReactive as vueShallowReactive } from '@vue/reactivity'
108
import type { Reactive, ShallowReactive } from '@vue/reactivity'
9+
import { useWatch } from './watch'
10+
import { useForceUpdate } from './_utils'
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/reactivity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Surmon <https://github.com/surmon-china>
44
*/
55

6-
import { useWatch } from './watch/watch'
6+
import { useWatch } from './watch'
77
import { useForceUpdate } from './_utils'
88

99
/**

0 commit comments

Comments
 (0)