Skip to content

Reactive properties and styles - #60

Open
panglesd wants to merge 14 commits into
let-def:masterfrom
panglesd:props-and-styles
Open

Reactive properties and styles#60
panglesd wants to merge 14 commits into
let-def:masterfrom
panglesd:props-and-styles

Conversation

@panglesd

@panglesd panglesd commented Feb 15, 2026

Copy link
Copy Markdown
Collaborator

Add reactive properties and styles.

Does not address #59, but reactive styles are unset when "not present anymore", while reactive props are not (as it would not make sense.

One of the commit is optional, it makes the API in some ways better (uses Brr.El.Prop.t) and worse (it requires a constructor to hide an existential type. Brr.El.Prop.t is restricted to basic types, but I did not find an example where an object type is needed). What do you think?

I also added two examples.

I'm not sure the dummy_value is a good OCaml pattern, but I kept it anyway! One step at a time!

It's probably good to review commit by commit. I tried to have a clean history. It starts with some refactoring to add abstractions to make adding styles and props easier. Then, styles, then props are added.

Also, notes that for the reason given in #54 (comment), I kept the distinction between props and attributes.

Ping @voodoos!

@voodoos voodoos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a first round of review, I have a good overall feeling about it.

I do like the use of 'a El.Prop.t which makes the api cleaner, but it is a shame that it requires wrapping... We are already putting P, R, S all other the place... P (P ...) is a bit confusing, `P (Prop ...) a bit verbose. Not sure what's the best approach here.

Comment thread lib/brr-lwd/elwd.ml Outdated
Comment thread lib/brr-lwd/elwd.ml
Comment thread lib/brr-lwd/elwd.mli Outdated
Comment on lines 27 to 32
@@ -26,11 +33,23 @@ val v : ?d:document -> ?at:At.t col -> ?ev:handler col -> tag_name -> t col -> t

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you do that in another commit, but we should document the new parameters, and maybe make the "same attrib more than once" behavior clearer. Also there is at least one typo we could fix: occurences, (Claude, where are thou !?)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is this Claude everyone is talking about?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with something but I could not find any docstring that would make the "same attrib more than once" behavior clearer...

Comment thread CHANGES Outdated
- Lwd.set: change binding before invalidation, otherwise the old value could be re-observed (reported by @voodoos)
- brr-lwd: support declarative events and set of css classes
- Nottui: fix treatment of some terminal events that were delayed because of improper buffer flushing, reported by @darrenldl
- brr-lwd: Fix handling of multiple reactive attributes (by @panglesd)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which issue does it fix if it is not #59 ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#53 fixes no opened issue!

In the last commit, I've fixed the changelog, and added the PR number to the changelog entries.

Comment thread lib/brr-lwd/elwd.ml
El.set_prop k v el
in
let dummy_kv = (Jstr.empty, Jv.undefined) in
let dummy_kv = P (El.Prop.width, 0) in

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that safe ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :( I don't like this dummy_value too much, but it is safe.

I did not do the effort to get rid of it, but please do if you prefer!

@panglesd

Copy link
Copy Markdown
Collaborator Author

I do like the use of 'a El.Prop.t which makes the api cleaner, but it is a shame that it requires wrapping... We are already putting P, R, S all other the place... P (P ...) is a bit confusing, `P (Prop ...) a bit verbose. Not sure what's the best approach here.

Not sure too. Also, Brr.El.Prop.t does not have an escape hatch for values other than bool, int, float, and jstr. This makes me pretty sad too.

Probably, the "less clean" api is the more pragmatic way to go... But I'm happy to be convinced otherwise (I tried it on slipshow, it was okayish but not much better. Brr.El.Prop has much fewer predefined properties than At, and I did have to convert strings to jstr anyway)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants