Skip to content

Binding refresh background task crashes if I try to use app.storage.user in binding backward function #3093

Closed Answered by rodja
JohanAR asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it seems that in backward/forward you do not have access to the app.storage. This might be related to #2520. A workaround may be archived like this:

class MyElement(ui.element):

    def __init__(self):
        super().__init__()
        self.a_value = False
        binding.bind_from(self, 'a_value', app.storage.general, 'a_value', backward=self.transform)

    def transform(self, new_value: bool) -> bool:
        self.classes(replace=('bg-yellow' if new_value else 'bg-red'))
        return new_value


@ui.page('/')
def index():
    with MyElement().classes('w-[400px]'):
        ui.switch('The value').bind_value(app.storage.general, 'a_value').bind_value(app.storage.user, 'do_invert')…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@JohanAR
Comment options

@falkoschindler
Comment options

@JohanAR
Comment options

Answer selected by JohanAR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants