Skip to content

Brr-lwd; reactive attributes have a poëted behavior #59

Description

@panglesd

Reactive attributes in brr-lwd have a strange semantic. See for instance this example (also available here)

let ui =
  let v = Lwd.var true in
  let click= Elwd.handler Ev.click (fun _ -> Lwd.update (not) v) in
  let button = Elwd.button ~ev:[`P click] [`P(El.txt' "Salut")] in
  let at1 =
    let$ b = Lwd.get v in
    if b then At.name (Jstr.v "name1")
    else At.title (Jstr.v "title1")
  in
  let at2 =
    let$ b = Lwd.get v in
    if not b then At.name (Jstr.v "name2")
    else At.title (Jstr.v "title2")
  in
  let el =
    Elwd.div ~at:[`R at1; `R at2] [
      `P (El.txt' "Try clicking the button and see how the attributes change.");
    ]
  in
  Elwd.div [ `R el; `R button ]

Basically at1 and at2 are two reactive attributes, depending on a reactive boolean. They set name or title depending on the boolean, but never the same (if b is true, at1 sets name and at2 sets title, if b is false, at1 sets title and at2 sets name)

This results in attributes being canceled when updating the boolean:

Peek.2026-02-14.16-52.webm

(expected behavior is to have (name=name1 AND title=title2) OR (name=name2 AND title=title1), not half of that)

It is tricky to fix. We could have the key not be reactive, but we probably have the same problem with sequences? We could have "absent" values not be unset, but have values as options (and None means unsetting). Those options are all breaking.

And I'm opening this as I'm working on reactive styles/properties. Especially in the prop values, unsetting when a prop is not present anymore is questionable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions