feat(effects): 添加懒执行选项和调度器支持
- 引入 ReactiveEffectOptions 接口,支持 lazy 和 scheduler 配置 - 实现懒执行功能,当 lazy 为 true 时不立即运行 effect - 添加新的示例文件 lazy.html 演示懒执行效果 - 优化 effect 函数参数结构,支持可选配置项
This commit is contained in:
@@ -13,9 +13,15 @@ type KeyToDepMap = Map<any, Dep>
|
||||
*/
|
||||
const targetMap = new WeakMap<any, KeyToDepMap>()
|
||||
|
||||
export function effect<T = any>(fn: () => T) {
|
||||
export interface ReactiveEffectOptions {
|
||||
lazy?: boolean
|
||||
schedler?: EffectScheduler
|
||||
}
|
||||
export function effect<T = any>(fn: () => T, options?: ReactiveEffectOptions) {
|
||||
const _effect = new ReactiveEffect(fn)
|
||||
_effect.run()
|
||||
if (!options || !options.lazy) {
|
||||
_effect.run()
|
||||
}
|
||||
}
|
||||
|
||||
export let activeEffect: ReactiveEffect | undefined
|
||||
|
||||
Reference in New Issue
Block a user