Giter VIP home page Giter VIP logo

Comments (4)

mrpmorris avatar mrpmorris commented on May 12, 2024

State should not have dependencies.

If you need state from somewhere else, you can create an EffectMethod that is triggered by StoreInitializedAction. The Effect can have that dependency injected, take the state it needs, and fire off an action to set up the state you need.

from fluxor.

aboutdomtime avatar aboutdomtime commented on May 12, 2024

Thanks.

However, as I mentioned using an Effect/EffectMethod on StoreInitializedAction get's called after my IImportantDependency is required.

To be more specific, I have a language lookup/localization service that I created for using in a Blazor server-side web application that I am working on.

Usage: @Localizer["Text"], where "Text" is the text to be localized. When a new language is selected, it triggers a Fluxor [action]. So in every component, ["Text",...] will be displayed in that newly selected language.

Since the service is needed while rendering the component, having an [action] set the state via a call to an [EffectMethod] on StoreInitializedAction will not work in this case.

I thought of a few possible solutions including (in order of best to worst):

  • Update the service/create Fake to echo the literal value of "Text" if all dependencies have not been initialized. So that I can do new FakeLocalizer() as an initial base state.

  • I can remove the service from AppState and just use a combination of [CascadingParameter], events, and [Inject] to get the desired result.

  • My least favorite--have the localizer property settable and inject IState<AppState> and ILocalizer in the constructor of a derived class of Effect<StoreInitializedAction>

from fluxor.

mrpmorris avatar mrpmorris commented on May 12, 2024

You could have your App component comsume state of your translation feature and not call @Body until State.Value.HasInitialized. That would only get set to true after the first time a language is set. That way you shouldn't have anything that requires your translation state values until after they've loaded.

from fluxor.

aboutdomtime avatar aboutdomtime commented on May 12, 2024

I think that's a great suggestion. I tried both methods, State.Value.HasInitialized and the FakeLocalizer and both seem to work just fine.

Thanks again.

from fluxor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.