Where is state stored in fluxor?

1.7k views Asked by At

I am new to working with state management. Currently I am working on a blazor application and I stumbled across the "fluxor" framework which allows state management via the flux pattern. Fluxor is working perfectly for me, however I can't seem to figure out where the State of a page is actually stored. Is it in cache, a db or some other fancy way? Is there a way for me to see that stored data in the browser?

I use fluxor on the client side of my application by the way.

Thanks for helping me out!

2

There are 2 answers

3
Tailslide On

State is kept in memory. You can view the state with a nice GUI by enabling Redux Devtools with .UseReduxDevTools() like this:

services.AddFluxor(o => o
    .ScanAssemblies(typeof(SomeType).Assembly)
    .UseReduxDevTools());

Then use the redux devtools addin:

https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en

enter image description here

If you wish to save the state to localstorage or a database I made a library to persist the state called Fluxor.Persist:

https://github.com/Tailslide/fluxor-persist

0
Peter Morris On

An IStore is instantiated as a Scoped dependency. Ultimately this is the root of everything for the current user.

When you inject IStore, IState<Whatever> IDispatcher, IActionSubscriber they will ultimately come from the state that is stored within that IStore instance.

If you inject IStore into something you can iterate through its Features property, which is a dictionary of IFeature keyed by name (the name being from IFeature.GetName).

The IFeature has an object GetState() method you can use to grab the state.

This is the non-generic way of accessing the state. The state is actually stored using generics.

Look at the ReduxDevTools code and you will see an example of how to get all state (to send to ReduxDevTools browser plugin) using IStore.Features and GetState

https://github.com/mrpmorris/Fluxor/blob/master/Source/Fluxor.Blazor.Web.ReduxDevTools/ReduxDevToolsMiddleware.cs#L67

and in the OnJumpToState method it shows how I restore historical states from the browser plugin

https://github.com/mrpmorris/Fluxor/blob/master/Source/Fluxor.Blazor.Web.ReduxDevTools/ReduxDevToolsMiddleware.cs#L92