LadderVM - size_calculator uses shared settings subscription

This commit is contained in:
John Colvin committed 2019-06-18 13:55:07 -05:00
1 parent c40055dd2f
commit a1ffc24ed9
2 files changed
+8 -7

No files matched your search

@@ -110,6 +110,7 @@ namespace mbts.spark {
if (Set(ref _show_account_position, s.account_position_visible, nameof(show_account_position)) | Set(ref _show_day_position, s.day_position_visible, nameof(show_day_position))) {
RaisePropertyChanged(nameof(position_display_text));
}
size_calculator.buttons = s.calculator_buttons;
}
};
PropertyAutoWrapper<LadderSettings, bool> bool_prop(string name, Func<LadderSettings, bool> get_bool) =>
@@ -132,7 +133,6 @@ namespace mbts.spark {
_dispose = Disposable.Create(
settings.OnDispatcher().Subscribe(settings_observer),
get_order_properties_editor_hooks(),
size_calculator = new CalculatorLogic(0, settings.Select(s => s.calculator_buttons).OnDispatcher()),
bus.subscribe(SparkTags.LogActivity).OnDispatcher().Subscribe(status_update),
// we need to hook this up to model.orders which is filtered for just the security
model.orders.OnDispatcher().Subscribe(working => {
@@ -275,7 +275,7 @@ namespace mbts.spark {
public double day_position => _day_position;
public ulong volume => _volume.Value;
public bool auto_clear { get => _auto_clear.Value; set => _auto_clear.set(value); }
public CalculatorLogic size_calculator { get; }
public CalculatorLogic size_calculator { get; } = new CalculatorLogic(0);
/// Important: <see cref="order_properties_vm"/> can be null.
public OrderPropertiesEditorVM order_properties_vm { get; }
public ObservableCollection<LadderOrderVM> orders { get; }
@@ -7,17 +7,18 @@ using System.Windows.Input;
namespace mbts.spark {
public class CalculatorLogic : DisposableViewModelBase {
readonly UserProperty<uint?> _value;
readonly Property<int[]> _buttons;
int[] _buttons;
public CalculatorLogic(uint? initial_size, IObservable<int[]> buttons_source) {
public CalculatorLogic(uint? initial_size) =>
_value = new UserProperty<uint?>(backing(nameof(value), initial_size));
_buttons = backing(nameof(buttons), buttons_source);
}
public CalculatorLogic(uint? initial_size, IObservable<int[]> buttons_source) : this(initial_size) =>
_dispose = buttons_source.Subscribe(newval => buttons = newval);
public uint? value { get => _value.Value; set => _value.Value = value; }
public bool value_setter_called => _value.setter_called;
public IObservable<uint?> value_observable => _value.Select(vals => vals.newval);
public int[] buttons { get => _buttons.Value; set => _buttons.set(value); }
public int[] buttons { get => _buttons; set => Set(ref _buttons, value); }
public ICommand click => new DelegateCommand<uint>(handle_calculator_click);
public ICommand set_value_command => new DelegateCommand<uint>(v => _value.Value = v);
public ICommand clear => new DelegateCommand(() => _value.Value = null);