Skip to content

feat: Add a Render Context API #3409

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

Merged
merged 6 commits into from
Apr 10, 2025
Merged

feat: Add a Render Context API #3409

merged 6 commits into from
Apr 10, 2025

Conversation

luanpotter
Copy link
Member

@luanpotter luanpotter commented Dec 14, 2024

Description

This provides a "context" API for components to share render-time information with indirect descendants.

Use cases can include:

  • the currentCamera value which is currently handled as a global list
  • shader rendering information (to replace the custom Canvas implementation from feat: Post Process API #3404)

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

@renancaraujo
Copy link
Member

Looking good. API wise it is good enough as an approach that it is not a breaking change.

It seems specific to the render phase, so I would add user-friendly error messages for when users try to access the context outside of render.
Also, should we name it RenderContext since it is so specific?

@luanpotter
Copy link
Member Author

@renancaraujo agree with both!

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

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

I'd just like some benchmark of the implication of adding this, other than that I think it looks good!

Copy link
Contributor

github-actions bot commented Jan 7, 2025

Benchmark Results

Package flame:

Benchmarks Current Branch
[luan.context-api]
Base Branch
[main]
Diff
Render Components Benchmark 1100.824 μs 1119.342 μs 🟢 -1.654 %
Updating Components Benchmark 387592.667 μs 399562.833 μs 🟢 -2.996 %

Benchmarks provided with 💙 by Dart Benchmark Action.

@luanpotter
Copy link
Member Author

(note: I will add a bench specifically about rendering when I have some time. this was just testing the waters with the action)

Copy link
Member

@renancaraujo renancaraujo left a comment

Choose a reason for hiding this comment

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

Merge eet

@luanpotter luanpotter changed the title feat: Add basic infrastructure for a Context API [PROPOSAL][WIP] feat: Add basic infrastructure for a Render Context API Apr 10, 2025
@luanpotter luanpotter changed the title feat: Add basic infrastructure for a Render Context API feat: Add a Render Context API Apr 10, 2025
@luanpotter
Copy link
Member Author

@renancaraujo I changed the name - but any idea how I could add a message if findRenderContext is called outside the render phase? only thing I can think of is to create a global counter or something 🙈

@luanpotter luanpotter marked this pull request as ready for review April 10, 2025 15:31
@spydon
Copy link
Member

spydon commented Apr 10, 2025

@renancaraujo I changed the name - but any idea how I could add a message if findRenderContext is called outside the render phase? only thing I can think of is to create a global counter or something 🙈

I think this is something we can handle by docs instead. So that we mention in both the dartdocs and the docs on the site that it should only be called from within the render-loop. I doubt many end-users will use the render context directly anyways?

@luanpotter
Copy link
Member Author

@spydon agreed. all concerns addressed, should we merge then?

@spydon
Copy link
Member

spydon commented Apr 10, 2025

@spydon agreed. all concerns addressed, should we merge then?

🚢-eeeeet!!

@luanpotter luanpotter enabled auto-merge (squash) April 10, 2025 17:09
@luanpotter luanpotter merged commit 532f019 into main Apr 10, 2025
15 of 16 checks passed
@luanpotter luanpotter deleted the luan.context-api branch April 10, 2025 17:28
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.

3 participants