Bind selection to immutablelist to get 1 instance/mutation

This commit is contained in:
John Colvin committed 2022-01-23 16:15:11 -05:00
1 parent 45a773fc69
commit 084cbfcef6
1 file changed
+28 -4
@@ -1,4 +1,4 @@
namespace mbts.spark {
namespace mbts.spark {
using bts;
using bts.api;
using bts.collections;
@@ -11,7 +11,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Reactive.Linq;
using System.Windows.Input;
@@ -465,17 +467,34 @@
name.GetHashCode();
}
public class VSSymbol : IEquatable<VSSymbol> {
public class VSSymbol : DisposableViewModelBase, IEquatable<VSSymbol> {
ImmutableList<string> _fitsi = ImmutableList<string>.Empty;
ImmutableList<string> _mastersi = ImmutableList<string>.Empty;
public VSSymbol(VSDriver driver, string name) {
this.driver = driver;
this.name = name;
_dispose = Disposable.Create(
fits.observe_immutable().OnDispatcher().Subscribe(f => fitsi = f),
masters.observe_immutable().OnDispatcher().Subscribe(m => mastersi = m));
}
public VSDriver driver { get; }
public string name { get; }
public bool is_selected { get; set; }
public ObservableCollection<string> fits { get; } = new();
public ImmutableList<string> fitsi {
get => _fitsi;
set => Set(ref _fitsi, value);
}
public ObservableCollection<string> masters { get; } = new();
public ImmutableList<string> mastersi {
get => _mastersi;
set => Set(ref _mastersi, value);
}
public VolSurfaceEnums.VolSurfacePricingModel pricing_model { get; set; }
public bool Equals(VSSymbol other) =>
@@ -488,7 +507,7 @@
name.GetHashCode();
}
public class VSSymbolGridVM {
public class VSSymbolGridVM : IDisposable {
public VSSymbolGridVM(VSDriver driver) {
this.driver = driver;
symbols = new ObservableCollection<VSSymbol>();
@@ -497,6 +516,9 @@
public VSDriver driver { get; private set; }
public string header { get { return "{0} ({1})".fmt(driver.name, driver.exchange); } }
public ObservableCollection<VSSymbol> symbols { get; private set; }
public void Dispose() =>
Disposable.dispose(symbols);
}
public class VSSymbolStructureVM : DisposableViewModelBase {
@@ -504,7 +526,9 @@
driver_grids = new ObservableCollection<VSSymbolGridVM>();
settings.core_settings.master_slave_relationships ??= new List<VolSurfaceSymbolRelationship>();
settings.core_settings.implied_vol_marketdata_relationships ??= new List<VolSurfaceSymbolRelationship>();
_dispose = bus.subscribe(SparkTags.ExpirationParametersInputTag).OnDispatcher().Subscribe(on_exp_params_input);
_dispose = new DisposableCombo(
bus.subscribe(SparkTags.ExpirationParametersInputTag).OnDispatcher().Subscribe(on_exp_params_input)) +
new Action(() => Disposable.dispose(driver_grids));
void on_exp_params_input(AnalyticsExpirationParametersMap data) {
var driver_map = data.get_option_driver_map();