Skip to content

switch global null to come from Nullable module and not Null #88

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

Merged
merged 2 commits into from
Mar 5, 2023

Conversation

zth
Copy link
Collaborator

@zth zth commented Mar 5, 2023

This changes the globally available null value to originate from Nullable rather than Null. Makes sense imo given that global null and undefined now originate from the same module.

It also makes working with domRefs in React more natural, allowing you to write null directly instead of Nullable.null:

@react.component
let make = () => {
  let divRef = React.useRef(null)
  <div ref={divRef->ReactDOM.Ref.domRef}> {"Hello"->React.string} </div>
}

(side note - would be cool to get completion for ReactDOM.Ref.* in the scenario below. Might be able to work that into the editor tooling)

Thoughts? cc @cknitt @glennsl

@zth zth force-pushed the global-null-from-nullable branch from 4d0cde5 to 6070da4 Compare March 5, 2023 08:44
@cknitt
Copy link
Member

cknitt commented Mar 5, 2023

I like it! 🙂

@glennsl
Copy link
Contributor

glennsl commented Mar 5, 2023

Ditto! :)

@zth zth merged commit ab9371a into main Mar 5, 2023
@zth zth deleted the global-null-from-nullable branch March 5, 2023 09:12
@cristianoc
Copy link
Contributor

What about typical bindings, is the idea that one most often encounters null | undefined | T, rather than null | T?
Asking as the few binding I looked at to add genType support to Core were using null | T.
Otherwise one has o bind with Null.t and will have most often to reach for Null.null.

@glennsl
Copy link
Contributor

glennsl commented Mar 5, 2023

Good question. I seems to recall the decision was made long ago to prefer Nullable.t over Null.t and Undefined.t, just for simplicity. I don't think React refs have ever been set to undefined, so I believe that is the reason why it's typed as it is.

I wonder if it would be practical to make Null.t a subtype of Nullable.t...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants