-
Notifications
You must be signed in to change notification settings - Fork 664
feature(rome_js_formatter): Inspect memoized content #2772
Conversation
7b4b142
to
6e63123
Compare
Deploying with Cloudflare Pages
|
6e63123
to
184dd70
Compare
184dd70
to
f31404a
Compare
f31404a
to
3110b82
Compare
@ematipico please merge the PR if you are happy with it as I'll be on PTO. |
@denbezrukov this or #2771 might be useful for you when testing if an element has a specific label. See the summary of this PR to when to use the |
/// | ||
/// let content = format_with(|f| { | ||
/// let mut counter = Counter::default().memoized(); | ||
/// let counter_content = counter.inspect(f)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API looks great! 🙀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started to ponder if we should rename VecBuffer
into ElementBuffer
. Vec
is way too generic, while it's actually the buffer where we want to write FormatElement
I'd like to keep |
I guess we agree to disagree. I think that the data structure should be inferred from its types, and the name should explain its intent/meaning. |
This PR adds the `inspect` method to `Memoized` that allows inspecting the formatted content. This can be useful in scenarios where some formatting must determine if some content will break to decide the best formatting. This is different from #2771 because the buffer should be preferred in cases where the fact whatever some content breaks is only used to determine the formatting of another element because it avoids interning/memoizing the inner content. The API shown here should be preferred when the formatting of the element itself depends on whatever its content breaks where using the `WillBreakBuffer` would need to rewind to the previous state.
a836c15
to
760ae40
Compare
Summary
This PR adds the
inspect
method toMemoized
that allows inspecting the formatted content.This can be useful in scenarios where some formatting must determine if some content will break to decide the best formatting.
This is different from #2771 because the buffer should be preferred in cases where the fact whatever some content breaks is only used to determine the formatting of another element because it avoids interning/memoizing the inner content.
The API shown here should be preferred when the formatting of the element itself depends on whatever its content breaks where using the
WillBreakBuffer
would need to rewind to the previous state.Test Plan
I added a new doc test showing how to use the new API