Skip to content
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

Missing unsubscribe #5

Open
mrpmorris opened this issue Aug 6, 2020 · 1 comment
Open

Missing unsubscribe #5

mrpmorris opened this issue Aug 6, 2020 · 1 comment
Labels
good first issue Good for newcomers

Comments

@mrpmorris
Copy link

https://github.com/JoeyMckenzie/BlazorConduit/blob/master/source/BlazorConduit.Client/Pages/Article/Article.razor#L79

This is a standard .NET event. If you don't remove your subscription then the store will keep a reference to your component instance and it will never be garbage collected, resulting in a memory leak.

Personally I wouldn't subscribe to the event. It's really only meant for people who can't descend from FluxorComponent (which you have).

I would change IsFollowing to a property:

private bool IsFollowing =>
  state.IsFollowingUser
  ?? state.CurrentArticle?.Author?.Following
  ?? false;
@JoeyMckenzie JoeyMckenzie added the good first issue Good for newcomers label Aug 10, 2020
@shashwatsingh
Copy link

Please suggest if other places using the StateChanged event handler need an update too.

Would removing the event-handler work on unmount? Otherwise, I can look at each of the pages
individually and try to follow the suggestion above.

I could try my hand at this and other page changes -- if they need to be changed
too -- depending on what is decided.

Other changes:

$  git grep "StateChanged"
Pages/Article/Article.razor:        ArticleState.StateChanged += OnArticleLoaded;
Pages/Article/ArticleList.razor:        ArticleState.StateChanged += UpdatePagination;
Pages/Article/EditPost.razor:            State.StateChanged += UpdateEditableFields;
Pages/Profile.razor:        ProfileState.StateChanged += RefreshProfileState;
Pages/Settings.razor:        State.StateChanged += OnCurrentUserAssigned;
Shared/CustomValidationForm.razor.cs:            State!.StateChanged += DisplayValidationErrors;
Shared/NavMenu.razor:        State.StateChanged += GetUsernameOnLoginOrRegistration;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants