Skip to content

Commit 72c52ad

Browse files
committed
Make EnvironmentObject disposable
1 parent adfff93 commit 72c52ad

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/Fabulous/Components/EnvironmentObject.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Fabulous
22

3+
open System
34
open System.Runtime.CompilerServices
45

56
type EnvironmentObjectRequest<'T> = delegate of unit -> EnvironmentKey<'T>
@@ -9,6 +10,11 @@ type EnvironmentObject() =
910
let changed = Event<unit>()
1011
member this.Changed = changed.Publish
1112
member this.NotifyChanged() = changed.Trigger()
13+
abstract member Dispose: unit -> unit
14+
default this.Dispose() = ()
15+
16+
interface IDisposable with
17+
member this.Dispose() = this.Dispose()
1218

1319
[<AutoOpen>]
1420
module EnvironmentObjectBuilders =

src/Fabulous/EnvironmentContext.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,9 @@ and [<AllowNullLiteral>] EnvironmentContext(logger: Logger, inheritedContext: En
8181

8282
if valuePropagationSubscription <> null then
8383
valuePropagationSubscription.Dispose()
84+
85+
for value in values.Values do
86+
if value :? IDisposable then
87+
(value :?> IDisposable).Dispose()
88+
89+
values.Clear()

0 commit comments

Comments
 (0)