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

ReactivePropertyの双方向バインド機能はありませんか? #227

Closed
zerodev1200 opened this issue Jun 23, 2024 · 2 comments
Closed

Comments

@zerodev1200
Copy link
Contributor

runceel/ReactivePropertyにあった、ToReactivePropertyAsSynchronized()と同じような双方向バインド機能を探しています。
下記はWPFで実行しています。

runceel/ReactiveProperty

public partial class MainWindow : Window
{
    public ReactiveProperty<int> A { get; } = new();
    public ReactiveProperty<int> B { get; } = new();
    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = this;
        var item = new Items();

        A = item.ToReactivePropertyAsSynchronized(x => x.Id);
        B = item.ToReactivePropertyAsSynchronized(x => x.Id);

        item.Id = 1;
        Debug.WriteLine($"item.Id:{item.Id}"); //1
        Debug.WriteLine($"a:{A.Value}"); //1
        Debug.WriteLine($"b:{B.Value}"); //1

        A.Value = 2;
        Debug.WriteLine($"item.Id:{item.Id}"); //2
        Debug.WriteLine($"a:{A.Value}"); //2
        Debug.WriteLine($"b:{B.Value}"); //2

        B.Value = 3;
        Debug.WriteLine($"item.Id:{item.Id}"); //3
        Debug.WriteLine($"a:{A.Value}"); //3
        Debug.WriteLine($"b:{B.Value}"); //3

        item.Id = 4;
        Debug.WriteLine($"item.Id:{item.Id}"); //4
        Debug.WriteLine($"a:{A.Value}"); //4
        Debug.WriteLine($"b:{B.Value}"); //4
    }

R3

public partial class MainWindow : Window
{
    public BindableReactiveProperty<int> A { get; } = new();
    public BindableReactiveProperty<int> B { get; } = new();
    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = this;
        var item = new Items();

        A = item.ObservePropertyChanged(x => x.Id).ToBindableReactiveProperty();
        B = item.ObservePropertyChanged(x => x.Id).ToBindableReactiveProperty();

        item.Id = 1;
        Debug.WriteLine($"item.Id:{item.Id}"); //1
        Debug.WriteLine($"a:{A.Value}"); //1
        Debug.WriteLine($"b:{B.Value}"); //1

        A.Value = 2;
        Debug.WriteLine($"item.Id:{item.Id}"); //1
        Debug.WriteLine($"a:{A.Value}"); //2
        Debug.WriteLine($"b:{B.Value}"); //1

        B.Value = 3;
        Debug.WriteLine($"item.Id:{item.Id}"); //1
        Debug.WriteLine($"a:{A.Value}"); //2
        Debug.WriteLine($"b:{B.Value}"); //3

        item.Id = 4;
        Debug.WriteLine($"item.Id:{item.Id}"); //4
        Debug.WriteLine($"a:{A.Value}"); //4
        Debug.WriteLine($"b:{B.Value}"); //4
    }
}

使い方が誤っているかもしれません。
お手数をおかけしますが、ご確認いただければ幸いです。

@neuecc
Copy link
Member

neuecc commented Jun 24, 2024

R3のReactivePropertyはミニマムなコア要素だけを提供したいと考えているため
フレームワーク的な高機能なものは入れない方針です。
なので、あるかどうかでいうと、ないですし、入れる予定もありませんになります。
どこまでをコア要素ととらえるかは難しいところですが、

  • パフォーマンスの観点も含めてclass ReactivePropertyそのものに実装を入れる必要がある

ものに関しては中に入れることを検討し、そうでないものは原則としては入れない、といったところでしょうか。

他力本願なことを言えば ReactiveProperty.R3 みたいなのが爆誕してくれると一番嬉しいのですけどね(?)@runceel

@neuecc neuecc closed this as completed Jun 24, 2024
@runceel
Copy link

runceel commented Jul 14, 2024

Please request features from here.
runceel/ReactiveProperty#487

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

No branches or pull requests

3 participants