Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support map.keys/map.values in bindings #20211

Closed
sigmundch opened this issue Jul 26, 2014 · 1 comment
Closed

Better support map.keys/map.values in bindings #20211

sigmundch opened this issue Jul 26, 2014 · 1 comment
Labels

Comments

@sigmundch
Copy link
Member

Right now map.keys/map.values return a new list every time they are requested. This can bring up issues in bindings where we might be comparing object's identities.

One idea is to cache the value and only return a new value when there are changes in the underlying Map. For example, doing something like the following in ObservableMap:

      /// Cache of keys so that only a new collection is created when we have reason
      /// to believe the keys have changed.
      Iterable<K> _keys;
      @­reflectable Iterable<K> get keys {
        if (_keys == null) _keys = _map.keys;
        return _keys;
      }
    
      /// Cache of keys so that only a new collection is created when we have reason
      /// to believe the values have changed.
      Iterable<V> _values;
      @­reflectable Iterable<V> get values {
        if (_values == null) _values = _map.values;
        return _values;
      }
    
      ...
    
      // Note: we don't really have a reasonable old/new value to use here.
      // But this should fix "keys" and "values" in templates with minimal overhead.
      void _notifyKeysValuesChanged() {
        _keys = null;
        notifyChange(new PropertyChangeRecord(this, #keys, null, null));
        _notifyValuesChanged();
      }
    
      void _notifyValuesChanged() {
        _values = null;
        notifyChange(new PropertyChangeRecord(this, #values, null, null));
      }
    }
 

This unfortunately departs from the semantics we got from dart:core Map, where keys/values are always a new instance.

Other ideas:
  - do something similar to the above, but also define observable iterables that can provide notifications for changes in the underlying map.

  - add logic to compare these collections more carefully in the binding layer.

Thoughts?

@DartBot
Copy link

DartBot commented Jun 5, 2015

This issue has been moved to dart-archive/observe#67.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants