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

ReactivePropertyで2度押し防止/ReactiveProperty v2.7.0をリリースしました

$
0
0

2度押し防止のための機能を追加しました。

www.nuget.org

名前はBusyNotifierです。

こんな感じで使います。

publicclass MainWindowViewModel
{
    private BusyNotifier BusyNotifier { get; } = new BusyNotifier();

    public ReactiveProperty<string> Output { get; } = new ReactiveProperty<string>();

    public ReactiveCommand ExecuteCommand { get; }

    public MainWindowViewModel()
    {
        this.ExecuteCommand = this.BusyNotifier
            .Select(x => !x)
            .ToReactiveCommand();

        this.ExecuteCommand.Subscribe(async _ =>
        {
            if (this.BusyNotifier.IsBusy) { return; }
            using (this.BusyNotifier.ProcessStart())
            {
                var result = await this.HeavyTaskAsync();
                this.Output.Value = result.ToString();
            }
        });
    }

    public async Task<DateTime> HeavyTaskAsync()
    {
        await Task.Delay(5000);
        return DateTime.Now;
    }
}

Viewing all articles
Browse latest Browse all 1387

Trending Articles



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