Do I need to use @observable in every field?

I noticed that if I don't use @observable in any of my UI codes, all field / member changes are automatically matched with data binding syntax.

The problem I am facing is to select one field in the class that extends WebComponent and applies the @observable annotation, now other fields do not correctly bind and display the changes.

Is this a known issue or correct functionality?

If I use the @observable annotation once, should I apply it to all fields?

+4
source share
3 answers

As mentioned in another post, you can mark the class with @observable .

Currently, you fall between the observed and the observers. Observers (and dispatch) are old ways that will soon be discontinued. Observatories are a new way. In order not to break old customers, we watched them. If you used at least one @observable , then the observer system is disabled.

A new implementation of MDV v2 is being prepared. I suggest you use @observable for everything you want to watch. Stop using dispatch() everywhere. Also, stop using top-level observable fields because they will not bind to node.

Apologies, things are really in a state of change. I suspect that everything will be settled soon.

I suggest reading more about MDV v2 here: https://github.com/toolkitchen/mdv/blob/stable/README.md to prepare for the changes.

I suspect that @observable will remain an option, so now continue to use this.

+4
source

From the documentation here , this seems to design me. The goal of @observable is to mark this member as interesting to bind, unlike others.

You can also annotate the @observable class @observable if you do not want to annotate each field separately: Marking a class as @observable is the same as marking all of its fields as @observable

+3
source

Today I made a good discovery about @observable : if you change the observed value outside the dart component code (using query("#component_id").xtag ), this field should be marked as @observable - otherwise the change to the value will not be noticed by the component .

Alternatively, after changing the value, dispatch() can be called. I am currently testing, which is faster, but I think it might be an annotation.

This is not a direct answer to the question, but it may be worth considering when deciding whether to use the annotation or not to use it.

+1
source

Source: https://habr.com/ru/post/1479306/


All Articles