Bind managed Block properties with read-only dependency tracking
Verify Tessera GUI / verify (push) Failing after 7m31s

This commit is contained in:
2026-10-21 21:19:36 +08:00
parent dff49770fa
commit 8d980745ea
11 changed files with 571 additions and 12 deletions
+31 -2
View File
@@ -214,6 +214,7 @@ enum Operation {
StateSet,
Increment,
TextOf,
Bind,
Text,
Rect,
Spacer,
@@ -609,7 +610,7 @@ impl NativeCallable for Function {
fn invoke(&self, cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
use Operation::*;
let (minimum, maximum) = match self.operation {
IsInstance | IsSubtype => (2, 2),
IsInstance | IsSubtype | Bind => (2, 2),
Stats | Viewport | Window | PageWindow | Mounts => (0, 0),
State | StateSet => (1, 1),
Increment => (0, 0),
@@ -967,6 +968,22 @@ impl NativeCallable for Function {
)?)));
}
let owner = self.owner.ok_or(invalid("method has no owner"))?;
if matches!(self.operation, Bind) {
let field = text(args.first())?;
let compute = object(args.get(1))?;
return Ok(NativeResult::Return(Value::Object(
crate::binding::connect(
cx,
owner,
&field,
compute,
self.session
.lock()
.map_err(|_| invalid("UI session poisoned"))?
.master,
)?,
)));
}
let (data_ref, data) = block::resolve(cx.store(), owner)?;
let mut data = data.clone();
let mut result = Value::Nil;
@@ -979,12 +996,14 @@ impl NativeCallable for Function {
}
*value = next;
data.text_binding = None;
cx.set_attr(owner, "text", args[0].clone())?;
}
_ => return Err(invalid("setText requires a text Block")),
},
SetColor => match &mut data.kind {
Kind::Text { color: value, .. } | Kind::Rect { color: value, .. } => {
*value = color(args.first(), "#242422")?
*value = color(args.first(), "#242422")?;
cx.set_attr(owner, "color", Value::Text(value.clone()))?;
}
_ => return Err(invalid("this Block has no color")),
},
@@ -1638,6 +1657,15 @@ impl UiBridge {
}
Ok(())
}
pub fn refresh_bindings(&self, vm: &mut Vm) -> Result<()> {
let nodes = self
.session
.lock()
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?
.nodes
.clone();
crate::binding::refresh(vm, &nodes)
}
pub fn prepare_frame(&self, vm: &mut Vm) -> Result<Option<Option<Arc<UiNode>>>> {
let changes = vm.take_changes();
let mut state = self
@@ -2126,6 +2154,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
vm.attach_type(function, function_type)?;
}
for (type_name, name, operation) in [
("Block", "bind", Operation::Bind),
("Block", "mounts", Operation::Mounts),
("Block", "invalidate", Operation::Invalidate),
("Block", "onClick", Operation::OnClick),