简体   繁体   English

在polymer.dart中更新动态计算的属性

[英]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. 我有一个场景,我有一个属性是使用polymer.dart进行数据绑定的,但是它没有自己的支持字段。 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. 在C#/ XAML中,NotifyPropertyChange不需要您传入新旧值,因此很容易解决。 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). 但是在polymer.dart中,我们确实需要始终传递旧值和新值,这对于动态评估的属性是不可能的(或者至少出于性能原因而不可取)。 How would we handle this in polymer.dart? 我们将如何在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. 我想一种解决方案是在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作为旧值应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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