-
-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Effects class instantiated twice? #33
Comments
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 |
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:
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. |
Sorry to have wasted your time. This behavior was caused by an error in my state class design, not related to Fluxor. |
Can you share any information so others can benefit? |
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:
So the passed value of foo was always ignored. |
Thanks :) |
In debugging an issue where state didn't appear to be affected by a dispatched action as expected following a page navigation, I found that an effects class (class with one or more methods marked [EffectMethod]) is instantiated twice. I'm new to Fluxor am not sure if this is expected, but it seems wrong. Is there any common mistake I could be making that would explain this behavior?
Most likely I don't completely understand how to share state between pages/components. I assumed that each time IState is injected into a component, it's always a reference to the same state object, so the state is already implicitly shared between pages. But maybe some special handling is required to accomplish this?
The text was updated successfully, but these errors were encountered: