Skip to content

Commit 7c31c4e

Browse files
committed
Merge branch 'new_workflow' of https://github.com/LibraStack/UnityMvvmToolkit into new_workflow
2 parents 39b48eb + 9678ea2 commit 7c31c4e

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

README.md

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -332,24 +332,20 @@ The following shows how to set up a simple command.
332332
using UnityMvvmToolkit.Core;
333333
using UnityMvvmToolkit.Core.Interfaces;
334334

335-
public class CounterViewModel : ViewModel
335+
public class CounterViewModel : IBindingContext
336336
{
337-
private int _count;
338-
339337
public CounterViewModel()
340338
{
339+
Count = new Property<int>();
340+
341341
IncrementCommand = new Command(IncrementCount);
342342
}
343343

344-
public int Count
345-
{
346-
get => _count;
347-
set => Set(ref _count, value);
348-
}
344+
public IProperty<int> Count { get; }
349345

350346
public ICommand IncrementCommand { get; }
351347

352-
private void IncrementCount() => Count++;
348+
private void IncrementCount() => Count.Value++;
353349
}
354350
```
355351

@@ -378,28 +374,27 @@ Key functionality:
378374
Let's say we want to download an image from the web and display it as soon as it downloads.
379375

380376
```csharp
381-
public class ImageViewerViewModel : ViewModel
377+
public class ImageViewerViewModel : IBindingContext
382378
{
379+
[Observable(nameof(Image))]
380+
private readonly IProperty<Texture2D> _image;
383381
private readonly IImageDownloader _imageDownloader;
384-
private Texture2D _texture;
385382

386383
public ImageViewerViewModel(IImageDownloader imageDownloader)
387384
{
385+
_image = new Property<Texture2D>();
388386
_imageDownloader = imageDownloader;
387+
389388
DownloadImageCommand = new AsyncCommand(DownloadImageAsync);
390389
}
391390

392-
public Texture2D Image
393-
{
394-
get => _texture;
395-
private set => Set(ref _texture, value);
396-
}
391+
public Texture2D Image => _image.Value;
397392

398393
public IAsyncCommand DownloadImageCommand { get; }
399394

400395
private async UniTask DownloadImageAsync(CancellationToken cancellationToken)
401396
{
402-
Image = await _imageDownloader.DownloadRandomImageAsync(cancellationToken);
397+
_image.Value = await _imageDownloader.DownloadRandomImageAsync(cancellationToken);
403398
}
404399
}
405400
```
@@ -420,7 +415,7 @@ With the related UI code.
420415
To disable the `BindableButton` while an async operation is running, simply set the `DisableOnExecution` property of the `AsyncCommand` to `true`.
421416

422417
```csharp
423-
public class ImageViewerViewModel : ViewModel
418+
public class ImageViewerViewModel : IBindingContext
424419
{
425420
public ImageViewerViewModel(IImageDownloader imageDownloader)
426421
{
@@ -433,7 +428,7 @@ public class ImageViewerViewModel : ViewModel
433428
If you want to create an async command that supports cancellation, use the `WithCancellation` extension method.
434429

435430
```csharp
436-
public class MyViewModel : ViewModel
431+
public class MyViewModel : IBindingContext
437432
{
438433
public MyViewModel()
439434
{
@@ -532,23 +527,22 @@ Then you can use the `ThemeModeToBoolConverter` as in the following example.
532527
Parameter value converter allows to convert a command parameter.
533528

534529
Built-in parameter value converters:
535-
- ParameterToStrConverter
536530
- ParameterToIntConverter
537531
- ParameterToFloatConverter
538532

539-
By default, the converter is not needed if your command has a `ReadOnlyMemory<char>` parameter type.
533+
By default, the converter is not needed if your command has a `string` parameter type.
540534

541535
```csharp
542-
public class MyViewModel : ViewModel
536+
public class MyViewModel : IBindingContext
543537
{
544538
public MyViewModel()
545539
{
546-
PrintParameterCommand = new Command<ReadOnlyMemory<char>>(PrintParameter);
540+
PrintParameterCommand = new Command<string>(PrintParameter);
547541
}
548542

549-
public ICommand<ReadOnlyMemory<char>> PrintParameterCommand { get; }
543+
public ICommand<string> PrintParameterCommand { get; }
550544

551-
private void PrintParameter(ReadOnlyMemory<char> parameter)
545+
private void PrintParameter(string parameter)
552546
{
553547
Debug.Log(parameter);
554548
}
@@ -568,9 +562,9 @@ If you want to create your own parameter value converter, create a class that in
568562
```csharp
569563
public class ParameterToIntConverter : ParameterValueConverter<int>
570564
{
571-
public override int Convert(ReadOnlyMemory<char> parameter)
565+
public override int Convert(string parameter)
572566
{
573-
return int.Parse(parameter.Span);
567+
return int.Parse(parameter);
574568
}
575569
}
576570
```
@@ -590,7 +584,7 @@ public class MyView : DocumentView<MyViewModel>
590584
Then you can use the `ParameterToIntConverter` as in the following example.
591585

592586
```csharp
593-
public class MyViewModel : ViewModel
587+
public class MyViewModel : IBindingContext
594588
{
595589
public MyViewModel()
596590
{
@@ -718,8 +712,8 @@ public class LabelViewModel : IBindingContext
718712
{
719713
public LabelViewModel()
720714
{
721-
IntValue = new ReadOnlyProperty<int>(55);
722-
StrValue = new ReadOnlyProperty<string>("69");
715+
IntValue = new Property<int>(55);
716+
StrValue = new Property<string>("69");
723717
}
724718

725719
public IReadOnlyProperty<int> IntValue { get; }
@@ -1036,10 +1030,14 @@ public abstract class BaseView<TBindingContext> : DocumentView<TBindingContext>
10361030
protected override IObjectProvider GetObjectProvider()
10371031
{
10381032
return new BindingContextObjectProvider(new IValueConverter[] { new IntToStrConverter() })
1039-
// Finds and warmups all classes that implement IBindingContext.
1033+
// Finds and warmups all classes from calling assembly that implement IBindingContext.
10401034
.WarmupAssemblyViewModels()
1035+
// Finds and warmups all classes from certain assembly that implement IBindingContext.
1036+
.WarmupAssemblyViewModels(Assembly.GetExecutingAssembly())
10411037
// Warmups a certain class.
10421038
.WarmupViewModel<CounterViewModel>()
1039+
// Warmups a certain class.
1040+
.WarmupViewModel(typeof(CounterViewModel))
10431041
// Creates 5 instances to rent 'IProperty<string>' without any allocations.
10441042
.WarmupValueConverter<IntToStrConverter>(5);
10451043
}

0 commit comments

Comments
 (0)