Skip to content

Commit

Permalink
Handle partial creation of DisposableAction (fixes #29) (#30)
Browse files Browse the repository at this point in the history
* Handle partial creation
  • Loading branch information
mrpmorris committed May 6, 2020
1 parent 9f3007a commit 4e37d31
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
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

0 comments on commit 4e37d31

Please sign in to comment.