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

Handle partial creation of DisposableAction (#fixes 29) #31

Merged
merged 2 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Docs/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Ensured add/remove on events are thread safe ([#23](https://github.com/mrpmorris/Fluxor/issues/23))
* Made it easier to find the source of DisposableCallback instances that are not disposed ([#24](https://github.com/mrpmorris/Fluxor/issues/24))
* State properties were not discovered if they were declared as private in a base class ([#25](https://github.com/mrpmorris/Fluxor/issues/25))
* Handle disposing of partially created DisposableAction ([#29](https://github.com/mrpmorris/Fluxor/issues/29))

### New in 3.1.0
* Used Newtonsoft entirely for JS interop to ReduxDevTools to prevent serialization errors ([#7](https://github.com/mrpmorris/Fluxor/issues/7))
Expand Down
4 changes: 3 additions & 1 deletion Source/Fluxor/DisposableCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public sealed class DisposableCallback : IDisposable
private readonly string Id;
private readonly Action Action;
private bool IsDisposed;
private bool WasCreated;

/// <summary>
/// Creates an instance of the class
Expand All @@ -30,6 +31,7 @@ public DisposableCallback(string id, Action action)

Id = id;
Action = action;
WasCreated = true;
}

/// <summary>
Expand All @@ -53,7 +55,7 @@ public void Dispose()
/// <exception cref="InvalidOperationException">Thrown if the object is collected without being disposed</exception>
~DisposableCallback()
{
if (!IsDisposed)
if (!IsDisposed && WasCreated)
throw new InvalidOperationException($"{nameof(DisposableCallback)} with Id \"{Id}\" was not disposed.");
}
}
Expand Down