Skip to content

Dirty doesn't send new value to the client after in-place modification #12

Description

@munozco

I don't really know if I misunderstood how it works, but calling dirty("field_name") on a StateDataModel doesn't actually send the value to the trame client after a in-place modification.

To solve this, I need to use flush({"field_name"}, force_push=True). Is this the correct thing to do ? Should we change the example in docs/getting_started.md ?

Here is a minimal reproducer:

from trame.app import TrameApp
from trame.app.dataclass import StateDataModel, Sync
from trame.ui.html import DivLayout
from trame.widgets import html


class InternalState(StateDataModel):
    integers = Sync(list[int], list)


class MyApp(TrameApp):
    def __init__(self, server=None, **_):
        super().__init__(server, "vue3", **_)
        self._data = InternalState(trame_server=self.server)
        self.build_ui()

    def build_ui(self):
        with DivLayout(self.server), self._data.provide_as("data"):
            html.Span("Integers : {{data.integers}}")
            html.Button("Add integer", click=self._add_int)

    def _add_int(self):
        self._data.integers.append(1)
        self._data.dirty("integers")  # Doesn't resend value to the client
        self._data.flush({"integers"}, force_push=True)  # Need to do this instead


if __name__ == "__main__":
    app = MyApp()
    app.server.start()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions