LoginSignup
2
0

More than 3 years have passed since last update.

型の違うReactivePropertyをCombineLatestしたい

Posted at

型の違うReactiveProperty

private StringReactiveProperty sentence = new StringReactiveProperty(string.Empty);
private BoolReactiveProperty flag = new BoolReactiveProperty(false);

どちらかに何かあったときに、両方の値を参照できるようにしたい。

普通にはCombineLatestできない

sentence.CombineLatest(flag).Subscribe((s, f) =>
  {
    // ERR
  }).AddTo(this);

Tupleで合成するといける

sentence.CombineLatest(flag, Tuple.Create).Subscribe(tuple =>
  {
    var (sentence, flag) = tuple;
    // OK
  }).AddTo(this);

Zip, ZipLatestはいける
Merge, Ambは無理

両方の変数が参照できる位置にあるなら、sentenceflagに同じ処理をSubscribeするのが楽でいいのかも。

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0