GFReactiveEffect¶
API Reference / Kernel / 类索引
- 路径:
addons/gf/kernel/core/gf_reactive_effect.gd - 模块:
Kernel - 继承:
RefCounted - API:
public - 类别:协议与扩展点 (
protocol) - 首次版本:
3.17.0
GFBindableProperty 的轻量响应式副作用。 监听一组 GFBindableProperty,在任意来源变化时执行回调。可绑定 Node 生命周期, 适合 Controller 层组合多个 Model 属性,不要求项目引入新的状态模型。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 信号 | effect_ran |
signal effect_ran(value: Variant) |
| 属性 | max_reruns_per_run |
var max_reruns_per_run: int = 8 |
| 方法 | _init |
func _init( sources: Array[GFBindableProperty] = [], callback: Callable = Callable(), owner: Node = null, run_immediately: bool = true ) -> void: |
| 方法 | configure |
func configure( sources: Array[GFBindableProperty], callback: Callable, owner: Node = null, run_immediately: bool = true ) -> void: |
| 方法 | run |
func run() -> Variant: |
| 方法 | stop |
func stop() -> void: |
| 方法 | dispose |
func dispose() -> void: |
| 方法 | is_active |
func is_active() -> bool: |
| 方法 | get_sources |
func get_sources() -> Array[GFBindableProperty]: |
信号¶
effect_ran¶
- API:
public
effect 执行后发出。 "type": "Variant", "description": "回调返回值。" }
参数:
| 名称 | 说明 |
|---|---|
value |
回调返回值。 |
结构:
value {:
属性¶
max_reruns_per_run¶
- API:
public
单次 run 中最多补跑的次数,避免回调持续写入来源属性造成死循环。
方法¶
_init¶
- API:
public
func _init( sources: Array[GFBindableProperty] = [], callback: Callable = Callable(), owner: Node = null, run_immediately: bool = true ) -> void:
构造函数。
参数:
| 名称 | 说明 |
|---|---|
sources |
要监听的 GFBindableProperty 列表。 |
callback |
变化后执行的回调。 |
owner |
可选 Node 生命周期宿主。 |
run_immediately |
是否立即执行一次。 |
configure¶
- API:
public
func configure( sources: Array[GFBindableProperty], callback: Callable, owner: Node = null, run_immediately: bool = true ) -> void:
配置并启动 effect。重复调用会先停止旧绑定。
参数:
| 名称 | 说明 |
|---|---|
sources |
要监听的 GFBindableProperty 列表。 |
callback |
变化后执行的回调。 |
owner |
可选 Node 生命周期宿主。 |
run_immediately |
是否立即执行一次。 |
run¶
- API:
public
手动执行 effect。 "type": "Variant", "description": "回调返回值;回调无效时返回 null。" }
返回:回调返回值;回调无效时返回 null。
结构:
return {:
stop¶
- API:
public
停止 effect 并断开全部监听。
dispose¶
- API:
public
释放 effect 持有的监听。
is_active¶
- API:
public
检查 effect 是否处于激活状态。
返回:激活时返回 true。
get_sources¶
- API:
public
获取当前监听的属性列表。
返回:GFBindableProperty 数组。