Skip to content

updated() broken? #397

Open
Open
@nerdoc

Description

@nerdoc

I experience problems with the component's update() method. I created a simple test component, with one counter property and an inc() method. And to update* methods:

class FooView(UnicornView):
    counter: int = 1

    def inc(self):
        self.counter += 1

    def updated_counter(self, value):
        print(f"updated_state: {value}")

    def updated(self, name, value):
        print(f"updated: {name}, {value}")

The html is just the {{ counter }} and a button that calls inc().

Now, after first launch (counter=1) I would suspect that after clicking on the button, counter becomes 2, and the server should output 2 lines:

updated: counter, 2
updated_counter: 2

But instead, it outputs:

updated_counter: 1

Problems:

  1. The updated() method is never called
  2. The updated_counter() method always outputs the last (!) value - the one before the change happens.

If i add another button with set unicorn:click="counter=4" in the button, and click oce the first (inc) button, and then that one, the output is:

updated_counter: 2
updated_counter: 4
updated: counter, 4

Ok, so after setting the property per frontend, at least the updated() method is called. But I would expect that when I do a self.counter += 1 too.
And I don't know why the updated_counter: 2 even is printed there. That's too late, it looks like it would have been waiting in a queue somewhere?

I tried unicorn 0.44.1, 0.42.0, 0.40.0, 0.37.0 just to get a few versions
Any clues? Am I doing something terribly wrong, or is this a (really severe?) bug?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions