-
Notifications
You must be signed in to change notification settings - Fork 90
Make unit
's JS representation undefined
, not {}
#266
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
Comments
I'm 👍🏻 on this as I think most folks (myself included) already think of We also already recommended using
|
I was almost sure that this was already part of the docs or at least that we had had this discussion elsewhere already, but apparently not (or at least, if we had the discussion before, I can't find it). I think there are two options here which we should distinguish:
My preference is 1, but I can see the argument for 2 as well. Option 2 is probably more desirable for the cypress problem that prompted this issue, admittedly; under option 1, you'd probably need to come up with a separate data type which could be guaranteed to have a runtime representation of |
Good news. I was able to reimplement the bindings slightly differently and remove the need for |
I believe in js FFI a more proper usage of the unit value would be: var unit = require("../Data.Unit/index.js").unit; To rely on a particular native representation would be more dangerous. |
I don’t think so; I think whatever we do, it should be safe to assume that |
Of course, it is better for the case of the Unit type to have a native referentially stable value. 42 could be used =). |
Here's my thoughts:
To be the most considerate towards others, we should notify those who might be relying on this by posting about this on Discourse, and wait a week or two. If someone is depending on it, we could count this as a breaking change. If we receive no such response, then let's make the change. While that week is passing, we could test this change out on real codebases to verify that nothing unexpectedly breaks by forking this repo or using a temporary branch. |
Where did this discussion happen on Discord? I don’t remember seeing those things mentioned. |
@hdgarrood The note about JSON serialization was mentioned here, but it seems like it isn't actually a problem. |
I've opened https://discourse.purescript.org/t/request-for-feedback-changing-unit-from-to-undefined/2522 to allow the wider community to respond. |
A little bit late I realize, but I want to clarify that returning no value in JS is exactly the same as returning |
Context
I was working on updating
purescript-cypress
to work withpurescript-spec-mocha
, so that something like this works:After bundling the file via
spago bundle-app
and running the resultingjs
file via Cypress, Cypress does not run the test at all and instead emits this error:Cypress detected that you invoked one or more cy commands but returned a different value.
The returned value was:
Because cy commands are asynchronous and are queued to be run later, it doesn't make sense to return anything else.
For convenience, you can also simply omit any return value or return
undefined
and Cypress will not error.In previous versions of Cypress we automatically detected this and forced the cy commands to be returned. To make tings less magical and clearer, we are now throwing an error. Learn more
This error only occurs if I use
purescript-spec-mocha
to generate thedescribe
andit
blocks around the actual tests. It's very possible thatpurescript-spec-mocha
(or a fork) could handle its FFI foritAsync
a bit differently.Regardless of why, should
unit
still be represented as{}
? Or should it be represented asundefined
? See also #223.I can't recall where, but I know in FFI somewhere, we used to do
return {};
for a function that returned unit. We later dropped that as we discovered that the object creation slowed down the FFI.The text was updated successfully, but these errors were encountered: