@hairy/react-lib-composition 1.49.0 → 1.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE.md → LICENSE} +1 -1
- package/README.md +363 -22
- package/package.json +3 -3
package/{LICENSE.md → LICENSE}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025-PRESENT Hairyf <https://github.com/
|
|
3
|
+
Copyright (c) 2025-PRESENT Hairyf <https://github.com/hairyf>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,36 +1,377 @@
|
|
|
1
|
-
# @hairy/react-lib
|
|
1
|
+
# @hairy/react-lib-composition
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[](https://npmjs.com/package/@hairy/react-lib-composition)
|
|
6
|
+
[](https://npm.chart.dev/@hairy/react-lib-composition)
|
|
7
|
+
[](https://bundlephobia.com/package/@hairy/react-lib-composition)
|
|
8
|
+
[](https://github.com/hairyf/hairylib/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
<!-- /automd -->
|
|
11
|
+
|
|
12
|
+
React reactivity layer built on top of `@vue/reactivity`.
|
|
8
13
|
|
|
9
14
|
## Install
|
|
10
15
|
|
|
16
|
+
<!-- automd:pm-install name="@hairy/react-lib-composition" -->
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
# ✨ Auto-detect
|
|
20
|
+
npx nypm install @hairy/react-lib-composition
|
|
21
|
+
|
|
22
|
+
# npm
|
|
23
|
+
npm install @hairy/react-lib-composition
|
|
24
|
+
|
|
25
|
+
# yarn
|
|
26
|
+
yarn add @hairy/react-lib-composition
|
|
27
|
+
|
|
28
|
+
# pnpm
|
|
29
|
+
pnpm add @hairy/react-lib-composition
|
|
30
|
+
|
|
31
|
+
# bun
|
|
32
|
+
bun install @hairy/react-lib-composition
|
|
33
|
+
|
|
34
|
+
# deno
|
|
35
|
+
deno install npm:@hairy/react-lib-composition
|
|
11
36
|
```
|
|
12
|
-
|
|
37
|
+
|
|
38
|
+
<!-- /automd -->
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
<!-- automd:jsdocs src="./src/index.ts" -->
|
|
43
|
+
|
|
44
|
+
### `computed(arg1, arg2)`
|
|
45
|
+
|
|
46
|
+
### `customRef(factory)`
|
|
47
|
+
|
|
48
|
+
Creates a customized ref with explicit control over its dependency tracking and updates triggering.
|
|
49
|
+
|
|
50
|
+
### `defineComponent()`
|
|
51
|
+
|
|
52
|
+
### `effectScope()`
|
|
53
|
+
|
|
54
|
+
Creates an effect scope object which can capture the reactive effects (i.e. computed and watchers) created within it so that these effects can be disposed together. For detailed use cases of this API, please consult its corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
|
|
55
|
+
|
|
56
|
+
### `Fragment`
|
|
57
|
+
|
|
58
|
+
- **Type**: `symbol`
|
|
59
|
+
- **Default**: `undefined`
|
|
60
|
+
|
|
61
|
+
### `getCurrentInstance()`
|
|
62
|
+
|
|
63
|
+
### `getCurrentScope()`
|
|
64
|
+
|
|
65
|
+
Returns the current active effect scope if there is one.
|
|
66
|
+
|
|
67
|
+
### `h()`
|
|
68
|
+
|
|
69
|
+
### `hasInjectionContext()`
|
|
70
|
+
|
|
71
|
+
### `inject()`
|
|
72
|
+
|
|
73
|
+
### `isProxy()`
|
|
74
|
+
|
|
75
|
+
### `isReactive()`
|
|
76
|
+
|
|
77
|
+
### `isReadonly()`
|
|
78
|
+
|
|
79
|
+
### `isRef()`
|
|
80
|
+
|
|
81
|
+
### `isShallow()`
|
|
82
|
+
|
|
83
|
+
### `markRaw()`
|
|
84
|
+
|
|
85
|
+
### `nextTick()`
|
|
86
|
+
|
|
87
|
+
### `onBeforeMount(fn)`
|
|
88
|
+
|
|
89
|
+
### `onBeforeUnmount(fn)`
|
|
90
|
+
|
|
91
|
+
The function is called right before the component is unmounted.
|
|
92
|
+
|
|
93
|
+
### `onBeforeUpdate(fn)`
|
|
94
|
+
|
|
95
|
+
### `onMounted(fn)`
|
|
96
|
+
|
|
97
|
+
The function is called right after the component is mounted.
|
|
98
|
+
|
|
99
|
+
### `onScopeDispose(fn, _failSilently)`
|
|
100
|
+
|
|
101
|
+
Registers a dispose callback on the current active effect scope. The callback will be invoked when the associated effect scope is stopped.
|
|
102
|
+
|
|
103
|
+
### `onUnmounted(fn)`
|
|
104
|
+
|
|
105
|
+
### `onUpdated(fn)`
|
|
106
|
+
|
|
107
|
+
The function is called immediately after the component is re-rendered with updated props or state. This method is not invoked during the initial render.
|
|
108
|
+
|
|
109
|
+
### `provide()`
|
|
110
|
+
|
|
111
|
+
### `reactive(target)`
|
|
112
|
+
|
|
113
|
+
### `reactivity(getter)`
|
|
114
|
+
|
|
115
|
+
Converts some of the 'raw Vue' data, which is not already wrapped in a hook, into reactive hook data to ensure proper reactivity within the component.
|
|
116
|
+
|
|
117
|
+
**Example:**
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
import React from 'react'
|
|
121
|
+
import { ref, reactivity } from 'veact'
|
|
122
|
+
|
|
123
|
+
const countRef = ref(0)
|
|
124
|
+
|
|
125
|
+
export const Component: React.FC = () => {
|
|
126
|
+
// Convert to a reactivity hook
|
|
127
|
+
const count = reactivity(() => countRef)
|
|
128
|
+
const increment = () => {
|
|
129
|
+
count.value++
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<div>
|
|
134
|
+
<span>{count.value}</span>
|
|
135
|
+
<button onClick={increment}>Increment</button>
|
|
136
|
+
</div>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
13
139
|
```
|
|
14
140
|
|
|
15
|
-
|
|
141
|
+
### `readonly(target)`
|
|
142
|
+
|
|
143
|
+
Takes an object (reactive or plain) or a ref and returns a readonly proxy to the original.
|
|
16
144
|
|
|
17
|
-
|
|
18
|
-
|
|
145
|
+
A readonly proxy is deep: any nested property accessed will be readonly as well. It also has the same ref-unwrapping behavior as {@link reactive()}, except the unwrapped values will also be made readonly.
|
|
146
|
+
|
|
147
|
+
**Example:**
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
const original = reactive({ count: 0 })
|
|
151
|
+
const copy = readonly(original)
|
|
152
|
+
|
|
153
|
+
useWatchEffect(() => {
|
|
154
|
+
// works for reactivity tracking
|
|
155
|
+
console.log(copy.count)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
// mutating original will trigger watchers relying on the copy
|
|
159
|
+
original.count++
|
|
160
|
+
|
|
161
|
+
// mutating the copy will fail and result in a warning
|
|
162
|
+
copy.count++ // warning!
|
|
19
163
|
```
|
|
20
164
|
|
|
165
|
+
### `ref(initValue?)`
|
|
166
|
+
|
|
167
|
+
### `shallowReactive(target)`
|
|
168
|
+
|
|
169
|
+
Shallow version of {@link reactive()}.
|
|
170
|
+
|
|
171
|
+
Unlike {@link reactive()}, there is no deep conversion: only root-level properties are reactive for a shallow reactive object. Property values are stored and exposed as-is - this also means properties with ref values will not be automatically unwrapped.
|
|
172
|
+
|
|
173
|
+
**Example:**
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
const state = shallowReactive({
|
|
177
|
+
foo: 1,
|
|
178
|
+
nested: {
|
|
179
|
+
bar: 2
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
// mutating state's own properties is reactive
|
|
184
|
+
state.foo++
|
|
185
|
+
|
|
186
|
+
// ...but does not convert nested objects
|
|
187
|
+
isReactive(state.nested) // false
|
|
188
|
+
|
|
189
|
+
// NOT reactive
|
|
190
|
+
state.nested.bar++
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### `shallowReadonly(target)`
|
|
194
|
+
|
|
195
|
+
Shallow version of {@link readonly()}.
|
|
196
|
+
|
|
197
|
+
Unlike {@link readonly()}, there is no deep conversion: only root-level properties are made readonly. Property values are stored and exposed as-is - this also means properties with ref values will not be automatically unwrapped.
|
|
198
|
+
|
|
199
|
+
**Example:**
|
|
200
|
+
|
|
201
|
+
```js
|
|
202
|
+
const state = shallowReadonly({
|
|
203
|
+
foo: 1,
|
|
204
|
+
nested: {
|
|
205
|
+
bar: 2
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
// mutating state's own properties will fail
|
|
210
|
+
state.foo++
|
|
211
|
+
|
|
212
|
+
// ...but works on nested objects
|
|
213
|
+
isReadonly(state.nested) // false
|
|
214
|
+
|
|
215
|
+
// works
|
|
216
|
+
state.nested.bar++
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### `shallowRef(initValue?)`
|
|
220
|
+
|
|
221
|
+
### `toRaw()`
|
|
222
|
+
|
|
223
|
+
### `toReactive()`
|
|
224
|
+
|
|
225
|
+
### `toReadonly()`
|
|
226
|
+
|
|
227
|
+
### `toRef()`
|
|
228
|
+
|
|
229
|
+
### `toRefs()`
|
|
230
|
+
|
|
231
|
+
### `toValue()`
|
|
232
|
+
|
|
233
|
+
### `TransitionGroup()`
|
|
234
|
+
|
|
235
|
+
### `unref()`
|
|
236
|
+
|
|
237
|
+
### `watch(source, callback, options)`
|
|
238
|
+
|
|
239
|
+
### `watchEffect(effect, options)`
|
|
240
|
+
|
|
241
|
+
Runs a function immediately while reactively tracking its dependencies and re-runs it whenever the dependencies are changed.
|
|
242
|
+
|
|
243
|
+
**Example:**
|
|
244
|
+
|
|
245
|
+
```js
|
|
246
|
+
const count = useRef(0)
|
|
247
|
+
watchEffect(() => console.log(count.value))
|
|
248
|
+
// -> logs 0
|
|
249
|
+
|
|
250
|
+
count.value++
|
|
251
|
+
// -> logs 1
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### `withEffectScope(fn, detached?)`
|
|
255
|
+
|
|
256
|
+
<!-- /automd -->
|
|
257
|
+
|
|
258
|
+
## Directory structure
|
|
259
|
+
|
|
260
|
+
<!-- automd:dir-tree imports=""maxDepth=2 -->
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
├── src/
|
|
264
|
+
│ ├── computed.ts
|
|
265
|
+
│ ├── effectScope.ts
|
|
266
|
+
│ ├── index.ts
|
|
267
|
+
│ ├── inject.ts
|
|
268
|
+
│ ├── lifecycle.ts
|
|
269
|
+
│ ├── reactive.ts
|
|
270
|
+
│ ├── reactivity.ts
|
|
271
|
+
│ ├── readonly.ts
|
|
272
|
+
│ ├── ref.ts
|
|
273
|
+
│ ├── watch.ts
|
|
274
|
+
│ └── watchEffect.ts
|
|
275
|
+
├── macros-global.d.ts
|
|
276
|
+
├── package.json
|
|
277
|
+
├── README.md
|
|
278
|
+
└── tsdown.config.ts
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
<!-- /automd -->
|
|
282
|
+
|
|
283
|
+
## Source
|
|
284
|
+
|
|
285
|
+
<!-- automd:file src="./src/index.ts" code lang="ts" -->
|
|
286
|
+
|
|
287
|
+
```ts [index.ts]
|
|
288
|
+
import { noop } from '@hairy/utils'
|
|
289
|
+
|
|
290
|
+
export * from './computed'
|
|
291
|
+
export * from './effectScope'
|
|
292
|
+
export * from './lifecycle'
|
|
293
|
+
export * from './reactive'
|
|
294
|
+
export * from './reactivity'
|
|
295
|
+
export * from './readonly'
|
|
296
|
+
export * from './ref'
|
|
297
|
+
export * from './watch'
|
|
298
|
+
export * from './watchEffect'
|
|
299
|
+
|
|
300
|
+
export {
|
|
301
|
+
isProxy,
|
|
302
|
+
isReactive,
|
|
303
|
+
isReadonly,
|
|
304
|
+
isRef,
|
|
305
|
+
isShallow,
|
|
306
|
+
markRaw,
|
|
307
|
+
toRaw,
|
|
308
|
+
toReactive,
|
|
309
|
+
toReadonly,
|
|
310
|
+
toRef,
|
|
311
|
+
toRefs,
|
|
312
|
+
toValue,
|
|
313
|
+
unref,
|
|
314
|
+
} from '@vue/reactivity'
|
|
315
|
+
export {
|
|
316
|
+
Fragment,
|
|
317
|
+
createElement as h,
|
|
318
|
+
} from 'react'
|
|
319
|
+
export const getCurrentInstance = noop
|
|
320
|
+
export const hasInjectionContext = noop
|
|
321
|
+
export const inject = noop
|
|
322
|
+
export const provide = noop
|
|
323
|
+
export const nextTick = noop
|
|
324
|
+
export const defineComponent = noop
|
|
325
|
+
export const TransitionGroup = noop
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
<!-- /automd -->
|
|
329
|
+
|
|
330
|
+
## Contributors
|
|
331
|
+
|
|
332
|
+
<!-- automd:contributors github="hairyf/hairylib" author="Hairyf" license="MIT" -->
|
|
333
|
+
|
|
334
|
+
Published under the [MIT](https://github.com/hairyf/hairylib/blob/main/LICENSE) license.
|
|
335
|
+
Made by [@Hairyf](https://github.com/Hairyf) and [community](https://github.com/hairyf/hairylib/graphs/contributors) 💛
|
|
336
|
+
<br><br>
|
|
337
|
+
<a href="https://github.com/hairyf/hairylib/graphs/contributors">
|
|
338
|
+
<img src="https://contrib.rocks/image?repo=hairyf/hairylib" />
|
|
339
|
+
</a>
|
|
340
|
+
|
|
341
|
+
<!-- /automd -->
|
|
342
|
+
|
|
21
343
|
## License
|
|
22
344
|
|
|
23
|
-
|
|
345
|
+
<!-- automd:fetch url="gh:hairyf/hairylib/main/LICENSE" -->
|
|
346
|
+
|
|
347
|
+
MIT License
|
|
348
|
+
|
|
349
|
+
Copyright (c) 2025-PRESENT Hairyf <https://github.com/hairyf>
|
|
350
|
+
|
|
351
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
352
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
353
|
+
in the Software without restriction, including without limitation the rights
|
|
354
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
355
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
356
|
+
furnished to do so, subject to the following conditions:
|
|
357
|
+
|
|
358
|
+
The above copyright notice and this permission notice shall be included in all
|
|
359
|
+
copies or substantial portions of the Software.
|
|
360
|
+
|
|
361
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
362
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
363
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
364
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
365
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
366
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
367
|
+
SOFTWARE.
|
|
368
|
+
|
|
369
|
+
<!-- /automd -->
|
|
370
|
+
|
|
371
|
+
<!-- automd:with-automd -->
|
|
372
|
+
|
|
373
|
+
---
|
|
24
374
|
|
|
25
|
-
|
|
375
|
+
_🤖 auto updated with [automd](https://automd.unjs.io)_
|
|
26
376
|
|
|
27
|
-
|
|
28
|
-
[npm-version-href]: https://npmjs.com/package/@hairy/react-lib
|
|
29
|
-
[npm-downloads-src]: https://img.shields.io/npm/dm/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669
|
|
30
|
-
[npm-downloads-href]: https://npmjs.com/package/@hairy/react-lib
|
|
31
|
-
[bundle-src]: https://img.shields.io/bundlephobia/minzip/@hairy/react-lib?style=flat&colorA=080f12&colorB=1fa669&label=minzip
|
|
32
|
-
[bundle-href]: https://bundlephobia.com/result?p=@hairy/react-lib
|
|
33
|
-
[license-src]: https://img.shields.io/github/license/hairyf/hairylib.svg?style=flat&colorA=080f12&colorB=1fa669
|
|
34
|
-
[license-href]: https://github.com/hairyf/hairylib/blob/main/LICENSE
|
|
35
|
-
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
|
|
36
|
-
[jsdocs-href]: https://www.jsdocs.io/package/@hairy/react-lib
|
|
377
|
+
<!-- /automd -->
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/react-lib-composition",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.51.0",
|
|
5
5
|
"description": "Library for react reactivity",
|
|
6
6
|
"author": "Hairyf <wwu710632@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"html-parse-stringify": "^3.0.1",
|
|
41
41
|
"mitt": "^3.0.1",
|
|
42
42
|
"valtio": "^2",
|
|
43
|
-
"@hairy/utils": "1.
|
|
43
|
+
"@hairy/utils": "1.51.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/react": "^19.1.3",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"react-dom": "^19.1.0",
|
|
50
50
|
"react-i18next": "^14.1.2",
|
|
51
51
|
"react-use": "^17.6.0",
|
|
52
|
-
"@hairy/react-lib": "1.
|
|
52
|
+
"@hairy/react-lib": "1.51.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "tsdown",
|