Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve null comparisons #1085

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -302,7 +302,7 @@ type Component(treeContext: ViewTreeContext, body: ComponentBody, context: Compo
node

member private this.RenderInternal() =
if _body = null then
if isNull body then
() // Component has been disposed
else
let prevRootWidget = _widget
Expand All @@ -320,10 +320,10 @@ type Component(treeContext: ViewTreeContext, body: ComponentBody, context: Compo
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 @@ -336,7 +336,7 @@ type Component(treeContext: ViewTreeContext, body: ComponentBody, context: Compo
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
Loading