Skip to content

Commit

Permalink
Merge pull request #250 from runceel/main
Browse files Browse the repository at this point in the history
v7.8.2
  • Loading branch information
runceel authored Mar 23, 2021
2 parents c69fcd4 + 5cb8c4f commit 53c7fdc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public TProperty GetPropertyPathValue()
public bool SetPropertyPathValue(TProperty value) => RootNode?.SetPropertyPathValue(value) ?? false;
public void SetSource(INotifyPropertyChanged source) => RootNode?.UpdateSource(source);

internal void RaisePropertyChanged() => _propertyChangedSource.OnNext(GetPropertyPathValue());
private void RaisePropertyChanged() => _propertyChangedSource.OnNext(GetPropertyPathValue());

private readonly Subject<TProperty> _propertyChangedSource = new Subject<TProperty>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public PropertyPathNode(string propertyName)

public string PropertyName { get; }
public object Source { get; private set; }
private Type PrevSourceType { get; set; }
public PropertyPathNode Next { get; private set; }
public PropertyPathNode Prev { get; private set; }
public void SetCallback(Action callback)
Expand All @@ -46,6 +47,11 @@ public void UpdateSource(object source)
EnsureDispose();
Cleanup();
Source = source;
if (PrevSourceType != Source?.GetType())
{
_getAccessor = null;
}
PrevSourceType = Source?.GetType();
StartObservePropertyChanged();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/SharedProperties.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<RootNamespace>Reactive.Bindings</RootNamespace>
<Version>7.8.1</Version>
<Version>7.8.2</Version>
<Authors>neuecc xin9le okazuki</Authors>
<PackageProjectUrl>https://github.com/runceel/ReactiveProperty</PackageProjectUrl>
<PackageTags>rx mvvm async rx-main reactive</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,55 @@ public void ObserveProperty()
{
Child = new Item
{
RefTypeValue = "xxx",
ValueTypeValue = 10,
Value = 10,
},
};

var testScheduler = new TestScheduler();
var testObserver = testScheduler.CreateObserver<int>();

var path = PropertyObservable.CreateFromPropertySelector(item, x => x.Child.ValueTypeValue);
var path = PropertyObservable.CreateFromPropertySelector(item, x => x.Child.Value);
path.Subscribe(testObserver);
path.GetPropertyPathValue().Is(10);
item.Child.ValueTypeValue = 1;
item.Child.Value = 1;

testObserver.Messages.Is(OnNext(0, 1));
item.IsPropertyChangedEmpty.IsFalse();
path.Dispose();
item.IsPropertyChangedEmpty.IsTrue();
item.Child.ValueTypeValue = 100;
item.Child.Value = 100;
testObserver.Messages.Is(OnNext(0, 1));
}

class Item : INotifyPropertyChanged
[TestMethod]
public void ChangeObserveSourcePropertyType()
{
var item = new Item
{
Child = new Item
{
Value = 10,
},
};

var testScheduler = new TestScheduler();
var testObserver = testScheduler.CreateObserver<int>();

var path = PropertyObservable.CreateFromPropertySelector(item, x => x.Child.Value);
path.Subscribe(testObserver);
path.GetPropertyPathValue().Is(10);
item.Child.Value = 1;
testObserver.Messages.Is(OnNext(0, 1));

item.Child = new AnotherItem
{
Value = 9999,
};
path.GetPropertyPathValue().Is(9999);
testObserver.Messages.Is(OnNext(0, 1), OnNext(0, 9999));
}

class ItemBase : INotifyPropertyChanged
{
public bool IsPropertyChangedEmpty => PropertyChanged == null;
private void SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
Expand All @@ -54,28 +81,24 @@ private void SetProperty<T>(ref T field, T value, [CallerMemberName] string prop
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

private string _refTypeValue;
public string RefTypeValue
{
get { return _refTypeValue; }
set { SetProperty(ref _refTypeValue, value); }
}

private int _valueTypeValue;
public int ValueTypeValue
private int _value;
public int Value
{
get { return _valueTypeValue; }
set { SetProperty(ref _valueTypeValue, value); }
get { return _value; }
set { SetProperty(ref _value, value); }
}

private Item _child;
public Item Child
private ItemBase _child;
public ItemBase Child
{
get { return _child; }
set { SetProperty(ref _child, value); }
}

public event PropertyChangedEventHandler PropertyChanged;
}
class Item : ItemBase { }
class AnotherItem: ItemBase { }
}

}
24 changes: 12 additions & 12 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 53c7fdc

Please sign in to comment.