public PageControllerModel( PageControllerToken token, ModuleActivator activator, PageControllerReducer reducer, SerialUtil serialUtil, MainReducer mainReducer, WindowPageHost windowPageHost, DatabaseManager databaseManager, DatabaseBackupService databaseBackupService ) { _activator = activator; _windowPageHost = windowPageHost; _databaseManager = databaseManager; _databaseBackupService = databaseBackupService; this._serialUtil = serialUtil; InitHandlers(); ActivateContent(token); this.WhenActivated((c) => { mainReducer.Select(state => state.FullscreenMode) .ObserveOnDispatcher(DispatcherPriority.Background) .Subscribe(isFullScreen => this.MenuVisibility = !isFullScreen) .DisposeWith(c); reducer.Select(state => state.SelectedPage) .Where(LambdaHelper.NotNull) .WithLatestFrom(reducer.Select(state => state.Controls), LambdaHelper.ToTuple) .ObserveOnDispatcher(DispatcherPriority.Background) .Subscribe(tuple => { var(selectedPage, controlsDict) = tuple; var controls = selectedPage == null ? new List <ButtonConfig>() : controlsDict.GetOrDefault(selectedPage.Id) ?? new List <ButtonConfig>(); SetActionButtons(controls); }) .DisposeWith(c); _serialUtil.ConnectionStatus .ObserveOnDispatcher(DispatcherPriority.Background) .Select(status => status.IsConnected) .Subscribe(status => { this.ReaderMenuText = status ? Localization["Отключить считыватель"] : Localization["Включить считыватель"]; }) .DisposeWith(c); }); }
public PageControllerEffects(PageControllerReducer reducer, SimpleEffectsMiddleware <GlobalState> effects, Storage storage) : base(effects, storage) { CreateEffect(actions => actions .OfType <RegisterControlsAction>() .WithLatestFrom(reducer.Select(state => state.Controls), LambdaHelper.ToTuple) .Select(tuple => { var(action, currentConfig) = tuple; var config = currentConfig; void Handle(object _, object __) { config.Remove(action.Token.Id); action.Token.Deactivated -= Handle; } action.Token.Deactivated += Handle; currentConfig = currentConfig.SetItem(action.Token.Id, action.Configs); return(reducer.SetActionId(new SetControlsAction(currentConfig))); }) ); }