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

Add set methods #58

Merged
merged 10 commits into from
Oct 28, 2022
Merged

Add set methods #58

merged 10 commits into from
Oct 28, 2022

Conversation

zunda-arrow
Copy link
Collaborator

This PR also optimizing how cloning works so components created with a decorator are never mutated. Im not sure how to best document this.

closes #47

@zunda-arrow zunda-arrow marked this pull request as ready for review October 25, 2022 19:40
@zunda-arrow
Copy link
Collaborator Author

zunda-arrow commented Oct 28, 2022

This may be too jank. This code would not work as expected.
It does follow a simple rule "functions will never be mutated" but idk. I don't think cloning is expensive enough to have this issue. Its so much cheaper than component.set() currently that you won't be slowing down functions that much.

@flare.button()
def button():
   ...

a = button.set_label("1234")
b = a.set_label("a")
c = a.set_label("b")

print(button.label)  # None
print(a.label)  # b
print(b.label)  # b
print(c.label)  # b

@zunda-arrow
Copy link
Collaborator Author

Another solution is requiring a method to be called before any changes to a button. Like .clone() or something. This would make it very explicit when a clone is made but it bloats up the API so I would rather clone everything and optimize later with rust/a custom clone function or something.

@zunda-arrow
Copy link
Collaborator Author

zunda-arrow commented Oct 28, 2022

Now whenever you mutate anything it clones. Cloning is at least 5x faster than the serializing method so its quite cheap really.

Copy link
Member

@hypergonial hypergonial left a comment

Choose a reason for hiding this comment

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

Cloning go brrrrr

@zunda-arrow zunda-arrow merged commit 42a1feb into brazier-dev:main Oct 28, 2022
@zunda-arrow zunda-arrow deleted the feat/set-methods branch October 28, 2022 20:42
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.

Set Component Attributes at Runtime
2 participants