Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use buffer to build stylesheet #511

Merged
merged 3 commits into from
Sep 15, 2024
Merged

Conversation

zakybilfagih
Copy link
Collaborator

Resolve #503 wohoo

Copy link

vercel bot commented Sep 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
styled-ppx ⬜️ Ignored (Inspect) Visit Preview Sep 15, 2024 2:40pm

Copy link
Owner

@davesnx davesnx left a comment

Choose a reason for hiding this comment

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

Cool PR @zakybilfagih

packages/runtime/native/CSS.ml Outdated Show resolved Hide resolved
packages/runtime/native/CSS.ml Outdated Show resolved Hide resolved
let render_declarations out rules =
let ls = rules |> Array.map ~f:Autoprefixer.prefix |> Array.flatten in
ls |> Array.iter ~f:(render_declaration out);
if Array.length ls > 0 then Buffer.truncate out (Buffer.length out - 1)
Copy link
Owner

Choose a reason for hiding this comment

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

Nice trick

let rules = rules_to_string rules in
push (Printf.sprintf "%s{%s}" selector rules)
let rules_to_string rules =
let out = Buffer.create 1024 in
Copy link
Owner

Choose a reason for hiding this comment

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

Just an idea, instead of passing the buffer everywhere, what do you think about passing a ~push callback? Not suggesting to do the change, but rather to discuss if you see it better or worst.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This could work, I guess the upside would be we are not dependent on Buffer.
Since we can push string and char, a possible solution would be using two callbacks ~pushc ~pushs, or maybe a polymorphic variant prop `string of string | `char of char ?

Copy link
Owner

Choose a reason for hiding this comment

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

meh, true. Not a big deal

@davesnx davesnx merged commit 9bdc299 into davesnx:main Sep 15, 2024
7 checks passed
pedrobslisboa added a commit to pedrobslisboa/styled-ppx that referenced this pull request Oct 1, 2024
* origin/main:
  feat: add backdrop-filter to webkit (davesnx#510)
  Add unicodeRange to fontFace (davesnx#513)
  Use buffer to build stylesheet (davesnx#511)
  feat: add backdrop-filter to webkit
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.

Remove all usages of Printf in native runtime
2 participants