Skip to content

Commit

Permalink
Merge pull request #418 from runceel/main
Browse files Browse the repository at this point in the history
Release v9.1.2
  • Loading branch information
runceel authored Mar 12, 2023
2 parents cc130f3 + c48f11d commit a3d03ab
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 118 deletions.
21 changes: 21 additions & 0 deletions Samples/Blazor/BlazorSample.Shared/Pages/Counter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@page "/counter"
@using Reactive.Bindings
@implements IDisposable
@inject CounterViewModel CounterViewModel

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @CounterViewModel.Counter.Value</p>

<button class="btn btn-primary"
@onclick="() => CounterViewModel.IncrementCommand.Execute()"
disabled="@CounterViewModel.IncrementCommand.IsDisabled()"
type="button">
Click me
</button>

@code {
public void Dispose() => CounterViewModel.Dispose();
}
13 changes: 6 additions & 7 deletions Samples/Blazor/BlazorSample.Shared/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

<h3>Validation sample</h3>

<EditForm Model="ValidationViewModel"
OnInvalidSubmit="ValidationViewModel.InvalidSubmitCommand.ToEvent<EditContext>()"
OnValidSubmit="ValidationViewModel.SubmitCommand.ToEvent<EditContext>()">
@*<EditForm Model="ValidationViewModel"
OnInvalidSubmit="() => ValidationViewModel.InvalidSubmitCommand.ExecuteAsync()"
OnValidSubmit="() => ValidationViewModel.SubmitCommand.ExecuteAsync()">
*@<EditForm Model="ValidationViewModel"
OnInvalidSubmit="() => ValidationViewModel.InvalidSubmitCommand.ExecuteAsync()"
OnValidSubmit="() => ValidationViewModel.SubmitCommand.ExecuteAsync()">
<ReactivePropertiesValidator />

<ValidationSummary />
Expand Down Expand Up @@ -59,10 +62,6 @@
{
ValidationViewModel.AddTo(_disposable);
HelloWorldViewModel.AddTo(_disposable);

HelloWorldViewModel.Output
.Subscribe(_ => InvokeAsync(StateHasChanged))
.AddTo(_disposable);
}

public void Dispose() => _disposable.Dispose();
Expand Down
31 changes: 31 additions & 0 deletions Samples/Blazor/BlazorSample.Shared/ViewModels/CounterViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Reactive.Disposables;
using Reactive.Bindings;
using Reactive.Bindings.Extensions;
using Reactive.Bindings.TinyLinq;

namespace BlazorSample.Shared.ViewModels;
public class CounterViewModel : IDisposable
{
private CompositeDisposable _disposables = new();
public ReactivePropertySlim<int> Counter { get; }

public ReactiveCommandSlim IncrementCommand { get; }

public CounterViewModel()
{
Counter = new ReactivePropertySlim<int>(0)
.AddTo(_disposables);

IncrementCommand = Counter.Select(x => x < 10)
.ToReactiveCommandSlim()
.WithSubscribe(Increment, _disposables.Add)
.AddTo(_disposables);
}

private void Increment()
{
Counter.Value++;
}

public void Dispose() => _disposables.Dispose();
}
18 changes: 0 additions & 18 deletions Samples/Blazor/BlazorServerApp/Pages/Counter.razor

This file was deleted.

1 change: 1 addition & 0 deletions Samples/Blazor/BlazorServerApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddTransient<ValidationViewModel>();
builder.Services.AddTransient<HelloWorldViewModel>();
builder.Services.AddTransient<CounterViewModel>();

var app = builder.Build();

Expand Down
18 changes: 0 additions & 18 deletions Samples/Blazor/BlazorWasmApp/Pages/Counter.razor

This file was deleted.

1 change: 1 addition & 0 deletions Samples/Blazor/BlazorWasmApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

builder.Services.AddTransient<ValidationViewModel>();
builder.Services.AddTransient<HelloWorldViewModel>();
builder.Services.AddTransient<CounterViewModel>();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

await builder.Build().RunAsync();
2 changes: 1 addition & 1 deletion Source/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<RootNamespace>Reactive.Bindings</RootNamespace>
<Version>9.1.1</Version>
<Version>9.1.2</Version>
<Authors>neuecc xin9le okazuki</Authors>
<PackageProjectUrl>https://github.com/runceel/ReactiveProperty</PackageProjectUrl>
<PackageTags>rx mvvm async rx-main reactive</PackageTags>
Expand Down
76 changes: 2 additions & 74 deletions Source/ReactiveProperty.Platform.Blazor/CommandExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Windows.Input;
using Microsoft.AspNetCore.Components;

namespace Reactive.Bindings;

Expand All @@ -8,82 +7,11 @@ namespace Reactive.Bindings;
/// </summary>
public static class CommandExtensions
{
/// <summary>
/// Convert from ReactiveCommand to EventCallback.
/// </summary>
/// <typeparam name="TValue">The type argument of EventCallback</typeparam>
/// <param name="command">The command</param>
/// <returns>EventCallback instance</returns>
public static EventCallback<TValue> ToEvent<TValue>(this ReactiveCommand command) => new EventCallback<TValue>(null, (TValue _) => command.Execute());

/// <summary>
/// Convert from ReactiveCommand to EventCallback.
/// </summary>
/// <typeparam name="TValue">The type argument of EventCallback</typeparam>
/// <param name="command">The command</param>
/// <returns>EventCallback instance</returns>
public static EventCallback<TValue> ToEvent<TValue>(this ReactiveCommand<TValue> command) => new EventCallback<TValue>(null, command.Execute);

/// <summary>
/// Convert from ReactiveCommand to EventCallback.
/// </summary>
/// <typeparam name="TValue">The type argument of EventCallback</typeparam>
/// <param name="command">The command</param>
/// <returns>EventCallback instance</returns>
public static EventCallback<TValue> ToEvent<TValue>(this ReactiveCommandSlim command) => new EventCallback<TValue>(null, (TValue _) => command.Execute());

/// <summary>
/// Convert from ReactiveCommand to EventCallback.
/// </summary>
/// <typeparam name="TValue">The type argument of EventCallback</typeparam>
/// <param name="command">The command</param>
/// <returns>EventCallback instance</returns>
public static EventCallback<TValue> ToEvent<TValue>(this ReactiveCommandSlim<TValue> command) => new EventCallback<TValue>(null, command.Execute);

/// <summary>
/// Convert from ReactiveCommand to EventCallback.
/// </summary>
/// <typeparam name="TValue">The type argument of EventCallback</typeparam>
/// <param name="command">The command</param>
/// <returns>EventCallback instance</returns>
public static EventCallback<TValue> ToEvent<TValue>(this AsyncReactiveCommand command) => new EventCallback<TValue>(null, (TValue _) => command.ExecuteAsync());

/// <summary>
/// Convert from ReactiveCommand to EventCallback.
/// </summary>
/// <typeparam name="TValue">The type argument of EventCallback</typeparam>
/// <param name="command">The command</param>
/// <returns>EventCallback instance</returns>
public static EventCallback<TValue> ToEvent<TValue>(this AsyncReactiveCommand<TValue> command) => new EventCallback<TValue>(null, command.ExecuteAsync);

/// <summary>
/// Convert from ReactiveCommand to EventCallback.
/// </summary>
/// <param name="command">The command</param>
/// <returns>EventCallback instance</returns>
public static EventCallback ToEvent(this ReactiveCommand command) => new EventCallback(null, () => command.Execute());

/// <summary>
/// Convert from ReactiveCommand to EventCallback.
/// </summary>
/// <param name="command">The command</param>
/// <returns>EventCallback instance</returns>
public static EventCallback ToEvent(this ReactiveCommandSlim command) => new EventCallback(null, () => command.Execute());

/// <summary>
/// Convert from ReactiveCommand to EventCallback.
/// </summary>
/// <param name="command">The command</param>
/// <returns>EventCallback instance</returns>
public static EventCallback ToEvent(this AsyncReactiveCommand command) => new EventCallback(null, () => command.ExecuteAsync());

/// <summary>
/// Return a boolean value that is inverted CanExecute method.
/// </summary>
/// <param name="command">The command.</param>
/// <returns>Inverted value of CanExecute method.</returns>
public static bool IsDisabled(this ICommand command)
{
return !command.CanExecute(null);
}
public static bool IsDisabled(this ICommand command) =>
!command.CanExecute(null);
}

0 comments on commit a3d03ab

Please sign in to comment.