-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
956ad15
commit fa43005
Showing
1 changed file
with
1 addition
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fa43005
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Luiz-Monad @alfonsogarciacaro Should it really be
IRefValue<'T> option
? Shouldn't it rather beIRefValue<'T option>
? AFAIK you never needIRefValue<'T> option
, because it will always exist and have acurrent
property (which may benull
, i.e. should be wrapped inoption
- strictly speaking, it would make most sense for theIRefValue
itself to be designed with anoption
wrapper forcurrent
).Is my understanding correct?
fa43005
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the way I'm using it, the ref "pointer" itself can be null, but I assume it can also be an object with the current property null. So I left it to the 'T definition to specify if the RefValue Current is nullable.
Indeed the type itself is
val ref : IRefValue<Browser.Types.Element option> option
.Perhaps that's overkill, but I don't trust things coming from JS, they always can be null.
fa43005
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually see forwardRef being used in this way in typescript.
And it's defined as
It can either be a RefObject of T or null and the current can also be either T or null. (bivariancehack is for inheritance in TS, ignore it). The function returns RefAttributes that matches it with
ref?
, it receives a nullable ref and returns an object with a ref, and that ref itself can either be nullable or the object that it points to can be nullable.So I guess that definition is correct, then I preferred to err on being too explicit than getting an undefined error at my face.
That would also work but needs changes to IRefValue type, it would more closely match the typescript definition, it sure makes more sense, but I didn't want to change other things. Also, createRef will always return it as non-null.
fa43005
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good to get that clarified.
Whether to have
current
be'T option
instead of'T
is up to @alfonsogarciacaro and other maintainers. AFAIK it would make the most sense, but it would also be a breaking change.fa43005
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it's true I haven't been always consistent about using F# options to represent nulls in JS but this is not always straightforward so I've my doubts now. Discussed here: fable-compiler/fable-browser#21
Recently I use
IRefValue
in combination withuseEffect
and at the point the effect is called is more or less guaranteed (if I'm not mistaken) the ref contains a value, that's why I didn't worry to much about that.