Skip to content

Commit

Permalink
Remove printfn
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Nov 16, 2024
1 parent 83e1f92 commit 572e850
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 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-pre11] - 2024-11-16

### Changed
- Replaced printfn statements with Logger.Log(Debug)

## [3.0.0-pre10] - 2024-11-14

### Changed
Expand Down Expand Up @@ -167,7 +172,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-pre10...HEAD
[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre11...HEAD
[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
[3.0.0-pre9]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre9
[3.0.0-pre8]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre8
Expand Down
4 changes: 2 additions & 2 deletions src/Fabulous/Components/Widget.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Component' =
| Some attr -> attr.Value :?> ComponentData
| None -> failwith "Component widget must have a body"

let envContext = new EnvironmentContext(envContext)
let envContext = new EnvironmentContext(treeContext.Logger, envContext)
let context = new ComponentContext()
let comp = new Component(Data.Key, envContext, treeContext, context, data.Body)
let struct (node, view) = comp.CreateView(ValueSome widget)
Expand All @@ -47,7 +47,7 @@ module Component' =
| Some attr -> attr.Value :?> ComponentData
| None -> failwith "Component widget must have a body"

let envContext = new EnvironmentContext(envContext)
let envContext = new EnvironmentContext(treeContext.Logger, envContext)
let context = new ComponentContext()
let comp = new Component(Data.Key, envContext, treeContext, context, data.Body)
let node = comp.AttachView(widget, view)
Expand Down
16 changes: 8 additions & 8 deletions src/Fabulous/EnvironmentContext.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ type EnvironmentValueChanged(originEnvId: Guid, fromUserCode: bool, key: string,
type EnvironmentKey<'T>(key: string) =
member this.Key = key

and [<AllowNullLiteral>] EnvironmentContext(inheritedContext: EnvironmentContext) =
and [<AllowNullLiteral>] EnvironmentContext(logger: Logger, inheritedContext: EnvironmentContext) =
let id = Guid.NewGuid()
let values = Dictionary<string, obj>()
let valueChanged = Event<EnvironmentValueChanged>()

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

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

new() = new EnvironmentContext(null)
new(logger: Logger) = new EnvironmentContext(logger, null)

member this.Id = id

Expand All @@ -46,7 +46,7 @@ and [<AllowNullLiteral>] EnvironmentContext(inheritedContext: EnvironmentContext
ValueNone

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

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

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

if valuePropagationSubscription <> null then
valuePropagationSubscription.Dispose()
2 changes: 0 additions & 2 deletions src/Fabulous/Runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type Runner<'arg, 'model, 'msg>(getState: unit -> 'model, setState: 'model -> un
let newModel, cmd = program.Update(lastMsg.Value, model)
let subs = program.Subscribe(newModel)

printfn $"Updating model. Was %A{model}, Is %A{newModel}"

setState newModel

_activeSubs <- Sub.Internal.diff _activeSubs subs |> Sub.Internal.Fx.change onError dispatch
Expand Down

0 comments on commit 572e850

Please sign in to comment.