« Fluxor » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 45 : | Ligne 45 : | ||
<filebox fn='Pages/Items.razor.cs'> | <filebox fn='Pages/Items.razor.cs'> | ||
[Inject] | public partial class Items : FluxorComponent | ||
private IState<ItemSearchState> ItemSearchState { get; set; } | { | ||
[Inject] | |||
private IState<ItemSearchState> ItemSearchState { get; set; } | |||
[Inject] | [Inject] | ||
public IDispatcher Dispatcher { get; set; } | public IDispatcher Dispatcher { get; set; } | ||
// get the state | // get the state | ||
ItemSearchState.Value.SearchText | ItemSearchState.Value.SearchText | ||
// update the state | // update the state | ||
Dispatcher.Dispatch(new ItemSearchAction(searchText)); | Dispatcher.Dispatch(new ItemSearchAction(searchText)); | ||
</filebox> | |||
<filebox fn='Pages/Items.razor'> | |||
@inherits Fluxor.Blazor.Web.Components.FluxorComponent | |||
</filebox> | </filebox> | ||
Version du 22 août 2023 à 00:13
Links
Example
Store/ItemSearchUseCase/ItemSearchCase.cs |
[FeatureState] public class TransactionsSearchState { public string SearchText { get; } = string.Empty; public TransactionsSearchState(string searchText) { SearchText = searchText; } // Required for creating initial state private TransactionsSearchState() { } } |
Store/ItemSearchUseCase/ItemSearchAction.cs |
public class TransactionsSearchAction { public string searchText { get; } = string.Empty; public TransactionsSearchAction(string searchText) { this.searchText = searchText; } } |
Store/ItemSearchUseCase/Reducers.cs |
public class Reducers { [ReducerMethod] public static ItemSearchState ReduceTransactionsSearchAction(ItemSearchState state, ItemSearchAction action) => new(action.searchText); } |
Pages/Items.razor.cs |
public partial class Items : FluxorComponent { [Inject] private IState<ItemSearchState> ItemSearchState { get; set; } [Inject] public IDispatcher Dispatcher { get; set; } // get the state ItemSearchState.Value.SearchText // update the state Dispatcher.Dispatch(new ItemSearchAction(searchText)); |
Pages/Items.razor |
@inherits Fluxor.Blazor.Web.Components.FluxorComponent |
Installation
dotnet add package Fluxor.Blazor.Web |
Program.cs |
builder.Services .AddFluxor(options => options.ScanAssemblies(typeof(Program).Assembly)); // options.UseReduxDevTools(); |
App.razor |
<Fluxor.Blazor.Web.StoreInitializer /> |