Giter Club home page Giter Club logo

Comments (6)

mrpmorris avatar mrpmorris commented on August 29, 2024

Hi

I looked at the source code to refresh my memory. Classes with [EffectMethod] methods in them are registered as Scoped, so you should get the same instance for every method in the same class. If you are seeing something different then I'll need to see a project that reproduces the problem.

You are correct about sharing state. If you inject IState<MyState> into more than one component then you should get the same state object. Again, if this is not what you are seeing then I'll need a project that reproduces the problem.

from fluxor.

pm64 avatar pm64 commented on August 29, 2024

Thank you @mrpmorris for the kind reply. Before I get too deep into creating an example project (which I'm more than happy to do), there's one part of my code that doesn't smell right, which might explain the issue.

In the aforementioned effects class, some of my EffectMethod handlers require access to the state, outside of what I supply in the action object. To make this possible, I inject IState into the effects class using a parameter on the effect class constructor. I then store a private reference to the state, which my methods access. In my mind this should work, but maybe it is the wrong approach?

I have traced the issue to this state reference in my effects class reflecting stale state data.

Example:

    private readonly IState<MyState> _myState;

    public Effects(IState<MyState> myState)
    {
        _myState = myState;
    }

    [EffectMethod]
    public async Task HandleMyAction(MyAction action, IDispatcher dispatcher)
    {
        var foo = _myState.Value.Blerg;
        ...
        dispatcher.Dispatch(new MyResultAction(...));
    }

The reason I don't simply pass the necessary parts of the state in the action object is that the effect requires access to tons of state properties, so instantiating the action object would be very cumbersome.

from fluxor.

pm64 avatar pm64 commented on August 29, 2024

Sorry to have wasted your time. This behavior was caused by an error in my state class design, not related to Fluxor.

from fluxor.

mrpmorris avatar mrpmorris commented on August 29, 2024

Can you share any information so others can benefit?

from fluxor.

pm64 avatar pm64 commented on August 29, 2024

Normally I would have, but in this case the error was pure stupidity on my part. My state class constructor basically had an error like this:

 class MyState {
      public int Foo { get; }
      public MyState(int foo)
      {
           Foo = foo;
           Foo = 0;
      }
 }

So the passed value of foo was always ignored.

from fluxor.

mrpmorris avatar mrpmorris commented on August 29, 2024

Thanks :)

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.