Skip to content

Object.is documentation #100

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

Closed
wants to merge 10 commits into from
Closed

Conversation

jmagaram
Copy link
Contributor

Documentation for Object.is. Also some tests mostly so I could verify how it all works. Took the liberty of documenting some of == and === at the same time. Read through the Mozilla docs and tried to summarize.

@jmagaram
Copy link
Contributor Author

According to Mozilla docs "In general, the only time Object.is special behavior towards zeros is likely to be of interest is in the pursuit of certain meta-programming schemes...suggested to avoid".

@zth
Copy link
Collaborator

zth commented Mar 15, 2023

This is looking great! Out traveling, but will try to review properly as soon as I can.

Comment on lines 8 to 10
The `==` operator [is different in ReScript than Javascript](https://rescript-lang.org/docs/manual/latest/overview#boolean). Arrays, records and other non-primitives are equal if they have the same contents (deep equality).

In ReScript, the `===` operator performs a strict equality check, like Javascript, and is similar but not identical to `is`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describing other functions and operators seem outside the scope of reference documentation. It will quickly become hard to maintain the documentation if it gets scattered across other definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks for the feedback.

```
*/
@val
external is: ('a, 'b) => bool = "Object.is"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this type signature makes sense. By definition you'd think that objects of different types wouldn't be considered identical, and you might as well weed that out at compile time.

There are of course exceptions, such as JSON-encoded primitives, but better to require explicitness than cater to convenience for weird edge cases I think.

I would therefore suggest this instead:

Suggested change
external is: ('a, 'b) => bool = "Object.is"
external is: ('a, 'a) => bool = "Object.is"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll change it.

@jmagaram
Copy link
Contributor Author

Git problems here. I broke the tests because I uploaded the type signature change but forgot to remove tests that compare different types. I don't know how to fix it. Sorry! Do I do a git pull rebase? VS Code wants me to do a Sync but it isn't working. Not sure what steps to do in VS Code. Don't want to lose work here. Or you can fix it if it is easy for you.

@jmagaram
Copy link
Contributor Author

Ok fixed it.

@jmagaram
Copy link
Contributor Author

Consolidated into #117

@jmagaram jmagaram closed this Jul 12, 2023
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.

3 participants