public QuestionBlockListViewModel(Api api, OptionsViewModel options) { _api = api; QuestionBlocks = new ReactiveList <QuestionBlockViewModel>(); var selectedSiteList = options.SelectedSites; selectedSiteList.Changed .Where(args => args.Action == NotifyCollectionChangedAction.Add) .SelectMany(args => args.NewItems .OfType <StackExchangeSite>() .Select(site => CreateQuestionBlock(site, options.QuestionsPerBlock))) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(block => QuestionBlocks.Add(block)); selectedSiteList.Changed .Where(args => args.Action == NotifyCollectionChangedAction.Remove) .SelectMany(args => args.OldItems .OfType <StackExchangeSite>() .Select(site => QuestionBlocks.FirstOrDefault(qb => qb.Site.api_site_parameter == site.api_site_parameter))) .Where(qb => qb != null) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(qb => QuestionBlocks.Remove(qb)); options.WhenAnyValue(o => o.UpdateInterval) .CombineLatest(options.WhenAnyValue(o => o.QuestionsPerBlock), (interval, questionCount) => new { interval, questionCount }) .Select(a => Observable.Interval(TimeSpan.FromMinutes(a.interval)) .Select(_ => a.questionCount) .StartWith(a.questionCount)) .Switch() .SelectMany(questionCount => ReloadAllQuestions(questionCount)) .Subscribe(); }
public void AddProcessInstance(IProcessInstanceViewModel instance) { var subscription = instance.ProcessTerminated.ObserveOnDispatcher().Subscribe(@event => { _processInstances.Remove(instance); }); _processInstances.Add(instance); }
internal void RemoveBubble(BubbleViewModel bubble) { if (bubble == null) { throw new ArgumentNullException("bubble"); } _bubblesInternal.Remove(bubble); }
protected BaseMenuViewModel(IAccountsService accountsService) { AccountsService = accountsService; DeletePinnedRepositoryCommand = new ReactiveCommand(); PinnedRepositories = new ReactiveList <PinnedRepository>(AccountsService.ActiveAccount.PinnnedRepositories); DeletePinnedRepositoryCommand.OfType <PinnedRepository>() .Subscribe(x => { AccountsService.ActiveAccount.PinnnedRepositories.RemovePinnedRepository(x.Id); PinnedRepositories.Remove(x); }); }
private void DoUpdate(IChangeSet <TObject, TKey> changes) { foreach (var change in changes) { switch (change.Reason) { case ChangeReason.Add: _target.Add(change.Current); break; case ChangeReason.Remove: _target.Remove(change.Current); break; case ChangeReason.Update: { _target.Remove(change.Previous.Value); _target.Add(change.Current); } break; } } }
protected BaseMenuViewModel(IAccountsService accountsService) { AccountsService = accountsService; DeletePinnedRepositoryCommand = ReactiveCommand.Create(); PinnedRepositories = new ReactiveList<PinnedRepository>(AccountsService.ActiveAccount.PinnnedRepositories); DeletePinnedRepositoryCommand.OfType<PinnedRepository>() .Subscribe(x => { AccountsService.ActiveAccount.PinnnedRepositories.Remove(x); AccountsService.Update(AccountsService.ActiveAccount); PinnedRepositories.Remove(x); }); }
/// <summary> /// Constructor when instantiating self-saving object /// </summary> /// <param name="path">Path to save</param> /// <param name="marshallManager">Marshaller dependency</param> public SystemMapping(string path, IMarshallManager marshallManager) { Mappings = new ReactiveList <Mapping> { ChangeTrackingEnabled = true }; Observable.Merge( Mappings.ItemChanged.Select(x => Unit.Default), Mappings.ItemsAdded.Select(x => Unit.Default), Mappings.ItemsRemoved.Select(x => Unit.Default) ).Sample(TimeSpan.FromSeconds(1)).Subscribe(x => Save(path, marshallManager)); // if mapping goes stale, remove it. Mappings.ItemChanged.Subscribe(e => { var mapping = e.Sender; if (mapping.IsStale) { Mappings.Remove(mapping); } }); }