feat(effects): 添加 scheduler 选项支持和 extend 工具函数

- 添加 extend 函数作为 Object.assign 的别名
- 修复 ReactiveEffectOptions 中 scheduler 属性拼写错误
- 实现 effect 选项配置的属性扩展功能
- 更新 lazy 示例展示 effect 运行逻辑
- 新增 scheduler 示例演示调度器功能
This commit is contained in:
dj
2026-02-10 17:54:23 +08:00
parent 62e40e7292
commit 1f50ab1c84
4 changed files with 45 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
import { createDep, Dep } from './dep'
import { isArray } from '@vue/shared'
import { extend, isArray } from '@vue/shared'
import { ComputedRefImpl } from './computed'
export type EffectScheduler = (...args: any[]) => any
@@ -15,10 +15,14 @@ const targetMap = new WeakMap<any, KeyToDepMap>()
export interface ReactiveEffectOptions {
lazy?: boolean
schedler?: EffectScheduler
scheduler?: EffectScheduler
}
export function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions) {
const _effect = new ReactiveEffect(fn)
if (options) {
extend(_effect, options)
}
if (!options || !options.lazy) {
_effect.run()
}