Skip to content

Instantly share code, notes, and snippets.

@adospace
Last active December 9, 2023 14:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adospace/cbede42c410c642dbdbcafe9ece5e90b to your computer and use it in GitHub Desktop.
Save adospace/cbede42c410c642dbdbcafe9ece5e90b to your computer and use it in GitHub Desktop.
MauiReactor + Fluxor POC
class MainPage : Component
{
protected override void OnMounted()
{
var store = Services.GetRequiredService<IStore>();
store.InitializeAsync().Wait();
var state = Services.GetRequiredService<IState<CounterState>>();
state.StateChanged += State_StateChanged;
base.OnMounted();
}
private void State_StateChanged(object sender, EventArgs e)
{
Invalidate();
}
public override VisualNode Render()
{
var state = Services.GetRequiredService<IState<CounterState>>();
return new ContentPage
{
new VStack
{
new Button(state.Value.ClickCount == 0 ? "Click me" : $"Clicked {state.Value.ClickCount} times!")
.OnClicked(OnButtonClicked)
.HCenter()
}
.VCenter()
};
}
private void OnButtonClicked()
{
var dispatcher = Services.GetRequiredService<IDispatcher>();
dispatcher.Dispatch(new IncrementCounterAction());
}
}
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiReactorApp<MainPage>(app =>
{
app.AddResource("Resources/Styles/Colors.xaml");
app.AddResource("Resources/Styles/Styles.xaml");
app.SetWindowsSpecificAssectDirectory("Assets");
})
.ConfigureSyncfusionCore()
#if DEBUG
.EnableMauiReactorHotReload()
#endif
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-SemiBold.ttf", "OpenSansSemiBold");
});
return builder.Build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment