Skip to content

Commit

Permalink
Merge pull request #1085 from kerams/main
Browse files Browse the repository at this point in the history
Improve null comparisons
  • Loading branch information
edgarfgp authored Nov 5, 2024
2 parents 5fcd382 + 348c6b1 commit 35c4ab4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Fabulous/Cmd.fs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ module Cmd =
fun (value: 'value) ->
[ fun dispatch ->
lock funLock (fun () ->
if cts <> null then
if not(isNull cts) then
cts.Cancel()
cts.Dispose()

Expand All @@ -209,7 +209,7 @@ module Cmd =
lock funLock (fun () ->
dispatch(fn value)

if cts <> null then
if not(isNull cts) then
cts.Dispose()
cts <- null)
},
Expand Down
8 changes: 4 additions & 4 deletions src/Fabulous/Component.fs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ type Component(componentDataKey: ScalarAttributeKey, treeContext: ViewTreeContex
node

member private this.RenderInternal() =
if _body = null then
if isNull body then
() // Component has been disposed
else
let prevRootWidget = _widget
Expand All @@ -322,10 +322,10 @@ type Component(componentDataKey: ScalarAttributeKey, treeContext: ViewTreeContex
Reconciler.update treeContext.CanReuseView (ValueSome prevRootWidget) currRootWidget viewNode

member this.Dispose() =
if _contextSubscription <> null then
if not(isNull _contextSubscription) then
_contextSubscription.Dispose()

if _context <> null then
if not(isNull _context) then
_context.Dispose()

_body <- null
Expand All @@ -338,7 +338,7 @@ type Component(componentDataKey: ScalarAttributeKey, treeContext: ViewTreeContex
member this.Dispose() = this.Dispose()

member this.Render(_) =
if _body = null then
if isNull _body then
() // Component has been disposed
else
treeContext.SyncAction(this.RenderInternal)
Expand Down
4 changes: 2 additions & 2 deletions src/Fabulous/View.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module View =
let fnWithBoxing (msg: obj) =
let oldFn = unbox<obj -> obj> oldAttr.Value

if msg <> null && typeof<'newMsg>.IsAssignableFrom(msg.GetType()) then
if not(isNull msg) && typeof<'newMsg>.IsAssignableFrom(msg.GetType()) then
box msg
else
oldFn msg |> unbox<'oldMsg> |> fn |> box
Expand All @@ -46,7 +46,7 @@ module View =

let defaultWith () =
let mappedFn (msg: obj) =
if msg <> null && typeof<'newMsg>.IsAssignableFrom(msg.GetType()) then
if not(isNull msg) && typeof<'newMsg>.IsAssignableFrom(msg.GetType()) then
box msg
else
unbox<'oldMsg> msg |> fn |> box
Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous/ViewNode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ type ViewNode =
if this.targetRef.IsAlive then
let comp = this.treeContext.GetComponent(this.targetRef.Target) :?> IDisposable

if comp <> null then
if not(isNull comp) then
comp.Dispose()
this.treeContext.SetComponent null this.targetRef.Target

Expand Down

0 comments on commit 35c4ab4

Please sign in to comment.