Skip to content

Commit

Permalink
Merge branch 'release/3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Nov 21, 2024
2 parents 8101b2d + a7cf443 commit af38ee2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

_No unreleased changes_

## [3.0.0-pre14] - 2024-11-21

### Added
- Unwrap EnvironmentAttributeKey for logging by @TimLariviere

## [3.0.0-pre13] - 2024-11-21

### Added
- Add IDisposable to EnvironmentObject by @TimLariviere

## [3.0.0-pre12] - 2024-11-20

### Added
Expand Down Expand Up @@ -177,7 +187,9 @@ _No unreleased changes_
### Changed
- Fabulous.XamarinForms & Fabulous.MauiControls have been moved been out of the Fabulous repository. Find them in their own repositories: [https://github.com/fabulous-dev/Fabulous.XamarinForms](https://github.com/fabulous-dev/Fabulous.XamarinForms) / [https://github.com/fabulous-dev/Fabulous.MauiControls](https://github.com/fabulous-dev/Fabulous.MauiControls)

[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre12...HEAD
[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre14...HEAD
[3.0.0-pre14]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre14
[3.0.0-pre13]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre13
[3.0.0-pre12]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre12
[3.0.0-pre11]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre11
[3.0.0-pre10]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre10
Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous/Builders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ type WidgetBuilder<'msg, 'marker when 'msg: equality> =
let attr =
{ Key = key
#if DEBUG
DebugName = $"Environment.{key}"
DebugName = let (EnvironmentAttributeKey key) = key in "Environment." + key
#endif
Value = value }

Expand Down
6 changes: 6 additions & 0 deletions src/Fabulous/Components/EnvironmentObject.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Fabulous

open System
open System.Runtime.CompilerServices

type EnvironmentObjectRequest<'T> = delegate of unit -> EnvironmentKey<'T>
Expand All @@ -9,6 +10,11 @@ type EnvironmentObject() =
let changed = Event<unit>()
member this.Changed = changed.Publish
member this.NotifyChanged() = changed.Trigger()
abstract member Dispose: unit -> unit
default this.Dispose() = ()

interface IDisposable with
member this.Dispose() = this.Dispose()

[<AutoOpen>]
module EnvironmentObjectBuilders =
Expand Down
12 changes: 9 additions & 3 deletions src/Fabulous/EnvironmentContext.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ and [<AllowNullLiteral>] EnvironmentContext(logger: Logger, inheritedContext: En
null
else
inheritedContext.ValueChanged.Subscribe(fun args ->
logger.Log(LogLevel.Debug, $"Env '{id}': Propagating '{args.Key}' change from '{args.OriginEnvId}'")
logger.Log(LogLevel.Debug, let (EnvironmentAttributeKey key) = args.Key in $"Env '{id}': Propagating '{key}' change from '{args.OriginEnvId}'")
valueChanged.Trigger(args))

new(logger: Logger) = new EnvironmentContext(logger, null)
Expand All @@ -46,7 +46,7 @@ and [<AllowNullLiteral>] EnvironmentContext(logger: Logger, inheritedContext: En
ValueNone

member internal this.SetInternal<'T>(key: EnvironmentAttributeKey, value: 'T, fromUserCode: bool) =
logger.Log(LogLevel.Debug, $"EnvironmentContext '{id}' set value '{key}' to '{value}'")
logger.Log(LogLevel.Debug, let (EnvironmentAttributeKey key) = key in $"EnvironmentContext '{id}' set value '{key}' to '{value}'")
let boxedValue = box value
values[key] <- boxedValue
valueChanged.Trigger(EnvironmentValueChanged(id, fromUserCode, key, ValueSome boxedValue))
Expand All @@ -68,7 +68,7 @@ and [<AllowNullLiteral>] EnvironmentContext(logger: Logger, inheritedContext: En
let fromUserCode = defaultArg fromUserCode true

if values.ContainsKey(key.Key) || inheritedContext = null then
logger.Log(LogLevel.Debug, $"EnvironmentContext '{id}' set value '{key.Key}' to '{value}'")
logger.Log(LogLevel.Debug, let (EnvironmentAttributeKey key) = key.Key in $"EnvironmentContext '{id}' set value '{key}' to '{value}'")
let boxedValue = box value
values[key.Key] <- boxedValue
valueChanged.Trigger(EnvironmentValueChanged(id, fromUserCode, key.Key, ValueSome boxedValue))
Expand All @@ -81,3 +81,9 @@ and [<AllowNullLiteral>] EnvironmentContext(logger: Logger, inheritedContext: En

if valuePropagationSubscription <> null then
valuePropagationSubscription.Dispose()

for value in values.Values do
if value :? IDisposable then
(value :?> IDisposable).Dispose()

values.Clear()

0 comments on commit af38ee2

Please sign in to comment.