コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: wizd/ReduxSimple
        public MainPage()
        {
            InitializeComponent();

            GoToCounterButton.Events().Click
            .Subscribe(_ =>
            {
                Frame.Navigate(typeof(CounterPage));
            });

            GoToTicTacToeButton.Events().Click
            .Subscribe(_ =>
            {
                Frame.Navigate(typeof(TicTacToePage));
            });

            GoToTodoListButton.Events().Click
            .Subscribe(_ =>
            {
                Frame.Navigate(typeof(TodoListPage));
            });

            GoToPokedexButton.Events().Click
            .Subscribe(_ =>
            {
                Frame.Navigate(typeof(PokedexPage));
            });

            GoToGitHubButton.Events().Click
            .Subscribe(async _ =>
            {
                var uri = new Uri("https://github.com/Odonno/ReduxSimple");
                await Launcher.LaunchUriAsync(uri);
            });

            OpenDevToolsButton.Events().Click
            .Subscribe(async _ =>
            {
                await Store.OpenDevToolsAsync();
            });

            // Extend view into title bar
            SetExtendViewIntoTitleBar(this, true);

            // Set TitleBar properties (colors)
            var titleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;

            titleBar.ButtonBackgroundColor         = Colors.Transparent;
            titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
            titleBar.ButtonHoverBackgroundColor    = Color.FromArgb(255, 72, 42, 203);
            titleBar.ButtonPressedBackgroundColor  = Color.FromArgb(200, 72, 42, 203);
            titleBar.ButtonForegroundColor         = Colors.Black;
        }
コード例 #2
0
        public CounterPage()
        {
            InitializeComponent();

            // Observe changes on state
            Store.Select(SelectCount)
            .UntilDestroyed(this)
            .Subscribe(count =>
            {
                CounterValueTextBlock.Text = count.ToString();
            });

            // Observe UI events
            IncrementButton.Events().Click
            .Subscribe(_ => Store.Dispatch(new IncrementAction()));

            DecrementButton.Events().Click
            .Subscribe(_ => Store.Dispatch(new DecrementAction()));

            // Initialize Documentation
            DocumentationComponent.LoadMarkdownFilesAsync("Counter");

            GoToGitHubButton.Events().Click
            .Subscribe(async _ =>
            {
                var uri = new Uri("https://github.com/Odonno/ReduxSimple/tree/master/ReduxSimple.Samples/Counter");
                await Launcher.LaunchUriAsync(uri);
            });

            OpenDevToolsButton.Events().Click
            .Subscribe(async _ =>
            {
                await Store.OpenDevToolsAsync();
            });

            ContentGrid.Events().Tapped
            .Subscribe(_ => DocumentationComponent.Collapse());
            DocumentationComponent.ObserveOnExpanded()
            .Subscribe(_ => ContentGrid.Blur(5).Start());
            DocumentationComponent.ObserveOnCollapsed()
            .Subscribe(_ => ContentGrid.Blur(0).Start());
        }
コード例 #3
0
        public PokedexPage()
        {
            InitializeComponent();

            // Observe changes on state
            Store.Select(
                CombineSelectors(SelectLoading, SelectIsPokedexEmpty)
                )
            .ObserveOnDispatcher()
            .Subscribe(x =>
            {
                var(loading, isPokedexEmpty) = x;

                OpenPokedexButton.ShowIf(!loading && isPokedexEmpty);

                GlobalLoadingProgressRing.IsActive = loading && isPokedexEmpty;
                GlobalLoadingProgressRing.ShowIf(loading && isPokedexEmpty);
                RootStackPanel.ShowIf(!isPokedexEmpty);
            });

            Store.Select(SelectSuggestions, 5)
            .ObserveOnDispatcher()
            .Subscribe(suggestions =>
            {
                AutoSuggestBox.ItemsSource = suggestions;
            });

            Store.Select(SelectPokemon)
            .ObserveOnDispatcher()
            .Subscribe(pokemon =>
            {
                PokemonPanel.ShowIf(pokemon.HasValue);
                PokemonIdTextBlock.Text   = pokemon.HasValue ? $"#{pokemon.Value.Id}" : string.Empty;
                PokemonNameTextBlock.Text = pokemon.HasValue ? pokemon.Value.Name : string.Empty;
                PokemonImage.Source       = pokemon.HasValue ? new BitmapImage(new Uri(pokemon.Value.Image)) : null;
            });

            Store.Select(SelectErrors)
            .ObserveOnDispatcher()
            .Subscribe(errors =>
            {
                ErrorsListView.ItemsSource = errors;
            });

            // Observe UI events
            OpenPokedexButton.Events().Click
            .ObserveOnDispatcher()
            .Subscribe(_ => Store.Dispatch(new GetPokemonListAction()));

            AutoSuggestBox.Events().TextChanged
            .ObserveOnDispatcher()
            .Subscribe(_ =>
            {
                Store.Dispatch(new UpdateSearchStringAction {
                    Search = AutoSuggestBox.Text
                });
            });

            AutoSuggestBox.Events().SuggestionChosen
            .ObserveOnDispatcher()
            .Subscribe(e =>
            {
                var selectedPokemonOption = (e.SelectedItem as PokemonGeneralInfo).ToOption();
                if (selectedPokemonOption.HasValue)
                {
                    AutoSuggestBox.Text = selectedPokemonOption.Value.Name;     // Avoid the automatic change of the Text property of SuggestBox
                    Store.Dispatch(new UpdateSearchStringAction {
                        Search = selectedPokemonOption.Value.Name
                    });
                }
            });

            // Register Effects
            Store.RegisterEffects(
                LoadPokemonList,
                LoadPokemonById,
                SearchPokemon
                );

            // Initialize Documentation
            DocumentationComponent.LoadMarkdownFilesAsync("Pokedex");

            GoToGitHubButton.Events().Click
            .Subscribe(async _ =>
            {
                var uri = new Uri("https://github.com/Odonno/ReduxSimple/tree/master/ReduxSimple.Samples/Pokedex");
                await Launcher.LaunchUriAsync(uri);
            });

            OpenDevToolsButton.Events().Click
            .Subscribe(async _ =>
            {
                await Store.OpenDevToolsAsync();
            });

            ContentGrid.Events().Tapped
            .Subscribe(_ => DocumentationComponent.Collapse());
            DocumentationComponent.ObserveOnExpanded()
            .Subscribe(_ => ContentGrid.Blur(5).Start());
            DocumentationComponent.ObserveOnCollapsed()
            .Subscribe(_ => ContentGrid.Blur(0).Start());
        }
コード例 #4
0
        public TodoListPage()
        {
            InitializeComponent();

            // Create backend properties
            var advancedCollectionView = new AdvancedCollectionView();

            advancedCollectionView.SortDescriptions.Add(new SortDescription("Id", SortDirection.Ascending));

            var selectedButtonStyle = App.Current.Resources["SelectedButtonStyle"] as Style;

            // Observe changes on state
            Store.Select(SelectFilter)
            .UntilDestroyed(this)
            .Subscribe(filter =>
            {
                switch (filter)
                {
                case TodoFilter.All:
                    advancedCollectionView.Filter = (_ => true);
                    break;

                case TodoFilter.Todo:
                    advancedCollectionView.Filter = (x => !((TodoItem)x).Completed);
                    break;

                case TodoFilter.Completed:
                    advancedCollectionView.Filter = (x => ((TodoItem)x).Completed);
                    break;
                }

                FilterAllButton.Style       = (filter == TodoFilter.All) ? selectedButtonStyle : null;
                FilterTodoButton.Style      = (filter == TodoFilter.Todo) ? selectedButtonStyle : null;
                FilterCompletedButton.Style = (filter == TodoFilter.Completed) ? selectedButtonStyle : null;
            });

            Store.Select(SelectItems)
            .UntilDestroyed(this)
            .Subscribe(items =>
            {
                if (TodoItemsListView.ItemsSource != advancedCollectionView)
                {
                    TodoItemsListView.ItemsSource = advancedCollectionView;
                }

                advancedCollectionView.Source = items;
            });

            // Observe UI events
            FilterAllButton.Events().Click
            .Subscribe(_ => Store.Dispatch(new SetFilterAction {
                Filter = TodoFilter.All
            }));
            FilterTodoButton.Events().Click
            .Subscribe(_ => Store.Dispatch(new SetFilterAction {
                Filter = TodoFilter.Todo
            }));
            FilterCompletedButton.Events().Click
            .Subscribe(_ => Store.Dispatch(new SetFilterAction {
                Filter = TodoFilter.Completed
            }));

            AddNewItemButton.Events().Click
            .Subscribe(_ => Store.Dispatch(new CreateTodoItemAction()));

            // Initialize Documentation
            DocumentationComponent.LoadMarkdownFilesAsync("TodoList");

            GoToGitHubButton.Events().Click
            .Subscribe(async _ =>
            {
                var uri = new Uri("https://github.com/Odonno/ReduxSimple/tree/master/ReduxSimple.Samples/TodoList");
                await Launcher.LaunchUriAsync(uri);
            });

            OpenDevToolsButton.Events().Click
            .Subscribe(async _ =>
            {
                await Store.OpenDevToolsAsync();
            });

            ContentGrid.Events().Tapped
            .Subscribe(_ => DocumentationComponent.Collapse());
            DocumentationComponent.ObserveOnExpanded()
            .Subscribe(_ => ContentGrid.Blur(5).Start());
            DocumentationComponent.ObserveOnCollapsed()
            .Subscribe(_ => ContentGrid.Blur(0).Start());
        }
コード例 #5
0
        public TicTacToePage()
        {
            InitializeComponent();

            // Get UI Elements
            var cellsGrids = CellsRootGrid.Children;

            // Observe changes on state
            Store.Select(
                CombineSelectors(SelectGameEnded, SelectWinner)
                )
            .Subscribe(x =>
            {
                var(gameEnded, winner) = x;

                YourTurnTextBlock.HideIf(gameEnded);
                StartNewGameButton.ShowIf(gameEnded);
                EndGameTextBlock.ShowIf(gameEnded);

                if (gameEnded)
                {
                    if (winner.HasValue)
                    {
                        EndGameTextBlock.Text = $"{winner.Value} won!";
                    }
                    else
                    {
                        EndGameTextBlock.Text = "It's a tie!";
                    }
                }
            });

            Store.Select(SelectCells)
            .Subscribe(cells =>
            {
                for (int i = 0; i < cells.Length; i++)
                {
                    var cellGrid  = cellsGrids[i] as Grid;
                    var textBlock = cellGrid.Children[0] as TextBlock;

                    if (cells[i].Mine.HasValue)
                    {
                        textBlock.Text = cells[i].Mine.Value ? "O" : "X";
                    }
                    else
                    {
                        textBlock.Text = string.Empty;
                    }
                }
            });

            // Observe UI events
            foreach (Grid cellGrid in cellsGrids)
            {
                cellGrid.Events().Tapped
                .Select(e =>
                {
                    var grid = e.OriginalSource as Grid;
                    return(new { Row = Grid.GetRow(grid), Column = Grid.GetColumn(grid) });
                })
                .Where(x =>
                {
                    var cell = Store.State.TicTacToe.Cells.First(c => c.Row == x.Row && c.Column == x.Column);
                    return(!Store.State.TicTacToe.GameEnded && !cell.Mine.HasValue);
                })
                .Subscribe(x =>
                {
                    Store.Dispatch(new PlayAction {
                        Row = x.Row, Column = x.Column
                    });
                });
            }

            StartNewGameButton.Events().Click
            .Subscribe(_ => Store.Dispatch(new StartNewGameAction()));

            // Initialize Components
            HistoryComponent.Initialize(Store);

            // Initialize Documentation
            DocumentationComponent.LoadMarkdownFilesAsync("TicTacToe");

            GoToGitHubButton.Events().Click
            .Subscribe(async _ =>
            {
                var uri = new Uri("https://github.com/Odonno/ReduxSimple/tree/master/ReduxSimple.Samples/TicTacToe");
                await Launcher.LaunchUriAsync(uri);
            });

            ContentGrid.Events().Tapped
            .Subscribe(_ => DocumentationComponent.Collapse());
            DocumentationComponent.ObserveOnExpanded()
            .Subscribe(_ => ContentGrid.Blur(5).Start());
            DocumentationComponent.ObserveOnCollapsed()
            .Subscribe(_ => ContentGrid.Blur(0).Start());
        }