Is a dart mix with a polymer observable field possible?

So let's say I have a mixin class defined as follows:

abstract class TestMix
{
  @observable bool loggedIn = false;

  updateLogin(){
    if (isLoggedIn()){
      loggedIn = true;
    }else{
      loggedIn = false;
    }
  }
}

I would like to mix this behavior with several kinds of polymer, so I:

@CustomTag('my-app')
class App extends PolymerElement with TestMix {

  App.created() : super.created() {
    this.updateLogin(); // @observable field 'loggedIn' is changed in the mixin
  }
}

I do not feel affection. If I move the mixin fields / methods directly to the App class, then everything works fine and the binding happens.

I just want to confirm whether this is possible or not? Can Dart reflect mixin fields like native fields? Or, if there is a way to manually trigger the binding (prefers not).

+4
source share
1 answer

Yes, you can. I found this way of working

 
abstract class TestMix implements Observable
{
  bool _loggedIn = false;

  @reflectable bool get loggedIn => _loggedIn;
  @reflectable set loggedIn(val) {
    _loggedIn = notifyPropertyChange(#loggedIn, _loggedIn, val);
  }

  updateLogin(){
    if (isLoggedIn()){
      loggedIn = true;
    }else{
      loggedIn = false;
    }
  }

  isLoggedIn() => true;
}

Using

@observable

mixin , , mixin Object, . - . /observ.dart.

@observable

mixin, .

, , , ,

import 'package:observe/mirrors_used.dart';

,

@reflectable

, Polymer

+4

All Articles