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

Do not mark dependent vars dirty if value did not change #4487

Open
benedikt-bartscher opened this issue Dec 5, 2024 · 1 comment
Open
Labels
enhancement Anything you want improved

Comments

@benedikt-bartscher
Copy link
Contributor

benedikt-bartscher commented Dec 5, 2024

import reflex as rx


class State(rx.State):
    _bcount: int = 0
    count: int = 0

    def increase(self):
        self._bcount += 1
        self.count += 1

    def touch(self):
        self._bcount = self._bcount
        self.count = self.count

    @rx.var(cache=True)
    def computed_bcount(self) -> str:
        return f"bcount: {self._bcount}"

    @rx.var(cache=True)
    def computed_count(self) -> str:
        return f"count: {self.count}"


def index() -> rx.Component:
    return rx.container(
        rx.text(State.computed_bcount),
        rx.text(State.computed_count),
        rx.button("Touch", on_click=State.touch),
        rx.button("Increase", on_click=State.increase),
    )


app = rx.App()
app.add_page(index)
Copy link

linear bot commented Dec 5, 2024

@benedikt-bartscher benedikt-bartscher changed the title Do not mark dependent vars if value did not change Do not mark dependent vars dirty if value did not change Dec 5, 2024
@Lendemor Lendemor added enhancement Anything you want improved and removed custom component request labels Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Anything you want improved
Projects
None yet
Development

No branches or pull requests

2 participants