Skip to content

Commit

Permalink
Merge branch 'main' into release/3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Jan 16, 2025
2 parents ec04597 + b2afa17 commit bd2fccc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 7 additions & 1 deletion 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-pre19] - 2025-01-16

### Changed
- Avoid memory allocation while writing logs in EnvironmentContext by @TimLariviere

## [3.0.0-pre18] - 2025-01-16

### Changed
Expand Down Expand Up @@ -211,7 +216,8 @@ _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-pre18...HEAD
[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre19...HEAD
[3.0.0-pre18]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre19
[3.0.0-pre18]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre18
[3.0.0-pre17]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre17
[3.0.0-pre16]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre16
Expand Down
15 changes: 9 additions & 6 deletions src/Fabulous/EnvironmentContext.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ and [<AllowNullLiteral>] EnvironmentContext(logger: Logger, inheritedContext: En

do
if inheritedContext = null then
logger.Log(LogLevel.Debug, $"EnvironmentContext '{id}' created")
logger.Debug("EnvironmentContext '{0}' created", id)
else
logger.Log(LogLevel.Debug, $"EnvironmentContext '{id}' created and inherited from '{inheritedContext.Id}'")
logger.Debug("EnvironmentContext '{0}' created and inherited from '{1}'", id, inheritedContext.Id)

let valuePropagationSubscription =
if inheritedContext = null then
null
else
inheritedContext.ValueChanged.Subscribe(fun args ->
logger.Log(LogLevel.Debug, let (EnvironmentAttributeKey key) = args.Key in $"Env '{id}': Propagating '{key}' change from '{args.OriginEnvId}'")
let (EnvironmentAttributeKey key) = args.Key
logger.Debug("Env '{0}': Propagating '{1}' change from '{2}'", id, key, args.OriginEnvId)
valueChanged.Trigger(args))

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

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

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

interface IDisposable with
member this.Dispose() =
logger.Log(LogLevel.Debug, $"EnvironmentContext '{id}' disposed")
logger.Debug("EnvironmentContext '{0}' disposed", id)

if valuePropagationSubscription <> null then
valuePropagationSubscription.Dispose()
Expand Down

0 comments on commit bd2fccc

Please sign in to comment.