简体   繁体   中英

Updating dynamically computed property in polymer.dart

I have a scenario where I have a property that is data-bound using polymer.dart, but it does not have its own backing field. Instead it is dynamically evaluated at run-time by logic which is dependent on a lot of other internal conditions. So when other logic dictates I want to tell the data-binding to update the value. In C#/XAML the NotifyPropertyChange does not require you to pass in old and new value so it is easy to solve this. But in polymer.dart we do need to pass old and new value always, which is not possible for a dynamically evaluated property (or at least not preferable for performance reasons). How would we handle this in polymer.dart?

Here is a pseudo example. The question is what I should put in the ??? fields?

class MyBoundClass extends Observable {

    void run() {
        ... logic, sets values in several internal non-observable objects...
        notifyPropertyChange(#status, ???, ???);
    }

    String get status {
        result = ... logic, evaluates values from several internal non-observable objects...
        return result;
    }
}

I guess one solution would be to simply introduce another backing field in MyBoundClass. But what I really want is just to update the binding and I don't see why it required to pass the old value. It seems to me that if you just want to update the binding, the old value is not relevant?

传递null作为旧值应该可以。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM