Skip to content

Commit

Permalink
Unwrap EnvironmentAttributeKey for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Nov 21, 2024
1 parent 6313533 commit a7cf443
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ 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
Expand Down Expand Up @@ -182,8 +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-pre13...HEAD
[3.0.0-pre12]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre13
[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: 3 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 Down

0 comments on commit a7cf443

Please sign in to comment.