Last active
February 27, 2016 16:06
-
-
Save ericdes/6793d5dad79334323d1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OK | |
private void AddTrade_Click(object sender, RoutedEventArgs e) | |
{ | |
var tradeCount = ViewModel.MyTrades.Count; | |
ViewModel.TradesSource.AddOrUpdate(Trade.Generate(tradeCount)); | |
} | |
// UPDATE NOT PROPAGATED TO VIEW | |
private void UpdateMarketPrice_Click(object sender, RoutedEventArgs e) | |
{ | |
ViewModel.MyTrades[0].SetMarketPrice(13); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Vm1 : ReactiveObject, IDisposable | |
{ | |
private readonly IDisposable _cleanup; | |
private readonly IObservableCache<Trade, long> _trades; | |
private ReadOnlyObservableCollection<Trade> _myTrades; | |
public ReadOnlyObservableCollection<Trade> MyTrades | |
{ | |
get { return _myTrades; } | |
} | |
public readonly SourceCache<Trade, long> TradesSource; | |
public Vm1() | |
{ | |
TradesSource = new SourceCache<Trade, long>(trade => trade.Id); | |
var tradesObservable = TradesSource.AsObservableCache(); | |
TradesSource.AddOrUpdate(Trade.Generate(0)); | |
_trades = TradesSource.AsObservableCache(); | |
var job = _trades.Connect() | |
.Bind(out _myTrades) | |
.Subscribe(); | |
_cleanup = new CompositeDisposable(_trades, TradesSource, job); | |
} | |
public void Dispose() | |
{ | |
_cleanup.Dispose(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This reduced code will to the same job