@formvk/reactive 0.1.0 → 1.0.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/src/tracker.ts DELETED
@@ -1,39 +0,0 @@
1
- import { effect, stop } from '@vue/reactivity'
2
- import type { ReactiveEffectRunner } from '@vue/reactivity'
3
-
4
- import type { Dispose } from './types'
5
-
6
- /**
7
- * 手动追踪器:track 时立即执行 view 并收集其中读取的响应式依赖,
8
- * 依赖变化时只触发 scheduler 通知外部,不会自动重跑 view,
9
- * 由外部(如 React 的 forceUpdate)决定何时再次调用 track。
10
- * 主要供 UI 框架在渲染期手动接管追踪时机。
11
- */
12
- export class Tracker {
13
- private runner: ReactiveEffectRunner<void>
14
- private view: () => unknown = () => undefined
15
- private result: unknown
16
-
17
- constructor(scheduler?: () => void) {
18
- // 构造时先空跑一次,真正的依赖收集发生在外部手动调用 track 时
19
- this.runner = effect(
20
- () => {
21
- this.result = this.view()
22
- },
23
- {
24
- // 无 scheduler 时也不能让 effect 自动重跑,保持「只通知、不执行」语义
25
- scheduler: scheduler ?? (() => {}),
26
- }
27
- )
28
- }
29
-
30
- /** 执行 view 并重新收集依赖,返回本次执行结果;可重复调用,依赖以最近一次为准 */
31
- track<T>(view: () => T): T {
32
- this.view = view
33
- this.runner()
34
- return this.result as T
35
- }
36
-
37
- /** 停止追踪并释放全部响应式依赖 */
38
- dispose: Dispose = () => stop(this.runner)
39
- }
package/src/types.ts DELETED
@@ -1,47 +0,0 @@
1
- export interface IChange {
2
- type: 'add' | 'set' | 'delete'
3
- key: PropertyKey
4
- value?: any
5
- oldValue?: any
6
- /** 内层 Vue reactive 对象,即变更发生的那个对象 */
7
- target: any
8
- /** 相对当前观察者视角的路径 */
9
- path: PropertyKey[]
10
- }
11
-
12
- export type Observer = (change: IChange) => void
13
-
14
- /** observe 回调中的变更描述,与 formily 的 DataChange 对齐 */
15
- export type DataChange = IChange
16
-
17
- export type Dispose = () => void
18
-
19
- export interface IReactionOptions<T> {
20
- /** 返回 true 表示新旧值相等,不触发 subscriber */
21
- equals?: (oldValue: T, newValue: T) => boolean
22
- /** 初始化后立即触发一次 subscriber */
23
- fireImmediately?: boolean
24
- }
25
-
26
- export type BindFunction<F = (...args: any[]) => any> = (callback?: F, context?: any) => F
27
-
28
- export type AnyFunction = (...args: any[]) => any
29
-
30
- /** 既是边界函数(直接调用),也可作为类成员装饰器使用 */
31
- export type Boundary = {
32
- <F extends AnyFunction>(
33
- value: F,
34
- context: ClassMethodDecoratorContext | ClassGetterDecoratorContext | ClassSetterDecoratorContext
35
- ): F
36
- (value: undefined, context: ClassFieldDecoratorContext): (initialValue: any) => any
37
- <T>(callback?: () => T): T
38
- bound: BindFunction
39
- }
40
-
41
- export interface IAction extends Boundary {
42
- scope: Boundary
43
- }
44
-
45
- export interface IBatch extends IAction {
46
- endpoint: (callback?: () => void) => void
47
- }
package/src/untracked.ts DELETED
@@ -1,10 +0,0 @@
1
- import { pauseTracking, resetTracking } from '@vue/reactivity'
2
-
3
- import { createBoundary } from './batch'
4
- import type { Boundary } from './types'
5
-
6
- /** 在回调执行期间暂停依赖收集,也支持 untracked.bound 绑定上下文 */
7
- export const untracked: Boundary = createBoundary(
8
- () => pauseTracking(),
9
- () => resetTracking()
10
- )
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "paths": {},
5
- "types": []
6
- },
7
- "include": ["./src/**/*.ts"],
8
- "exclude": ["./src/**/__tests__/**", "./__tests__/**"]
9
- }
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "include": ["./src/**/*.ts", "./test/**/*.ts"]
4
- }
package/vite.config.ts DELETED
@@ -1,39 +0,0 @@
1
- import swc from '@rollup/plugin-swc'
2
- import { defineConfig, withFilter } from 'vite'
3
- import dts from 'vite-plugin-dts'
4
-
5
- export default defineConfig({
6
- plugins: [
7
- dts({ tsconfigPath: './tsconfig.build.json', entryRoot: 'src', bundleTypes: true }),
8
- withFilter(
9
- swc({
10
- swc: {
11
- jsc: {
12
- parser: { syntax: 'typescript', decorators: true },
13
- transform: {
14
- // 使用 2023-11 版标准装饰器;插件默认值是 legacyDecorator: true,需显式关闭
15
- legacyDecorator: false,
16
- decoratorVersion: '2023-11',
17
- },
18
- },
19
- },
20
- }),
21
- // 仅当文件包含装饰器时才运行此转换
22
- { transform: { code: /^\s*@[\w$.]+/m } }
23
- ),
24
- ],
25
- build: {
26
- lib: {
27
- entry: 'src/index.ts',
28
- name: 'Formvk.Core',
29
- fileName: 'index',
30
- formats: ['es'],
31
- },
32
- minify: false,
33
- sourcemap: true,
34
- target: 'esnext',
35
- rollupOptions: {
36
- external: ['@vue/reactivity'],
37
- },
38
- },
39
- })