Quantcast
Channel: かずきのBlog@hatena
Viewing all articles
Browse latest Browse all 1387

Throttleの間隔を別のRxPropから動的に指定したい

$
0
0

こんなつぶやきを見たので。

書いてみたけど、こんな感じかなぁ?

publicclass MainWindowViewModel : BindableBase
{
    public ReactiveProperty<string> Input { get; private set; }

    private ReactiveProperty<string> output;

    public ReactiveProperty<string> Output
    {
        get { returnthis.output; }
        set { this.SetProperty(refthis.output, value); }
    }

    public ReactiveProperty<int> Interval { get; private set; }

    public MainWindowViewModel()
    {
        this.Input = new ReactiveProperty<string>();
        this.Interval = new ReactiveProperty<int>();
        this.Interval.Subscribe(v =>
        {
            var initialValue = default(string);
            if (this.Output != null)
            {
                initialValue = this.Output.Value;
                this.Output.Dispose();
            }
            this.Output = this.Input.Throttle(TimeSpan.FromSeconds(v)).ToReactiveProperty(initialValue);
        });
    }
}

Viewing all articles
Browse latest Browse all 1387

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>