Comments (5)
I concur, all the mess I made lately around async testing was due to the fact that I was passing a block instead of function into the setTimeout
method.. It made me think that PhantomJS executes setTimeout
immediately whereas it was due to this thing :-)
from scala-js-dom.
PR welcome.
Note that
def setTimeout(handler: () => Unit, timeout: Int): Int = ???
is incorrect, it must be a js.Function0
. Besides, Unit
return types in callbacks should typically be Any
instead, so it should be:
def setTimeout(handler: js.Function0[Any], timeout: Int): Int = ???
from scala-js-dom.
Besides, Unit return types in callbacks should typically be Any instead
@sjrd I have a question about this. I always thought it to be better, if we could specify the API author's intent more clearly. So, when a function argument is not expected to return a meaningful value, I've preferred to use () => Unit
, rather than js.Function0[Any]
.
Should I change such APIs to allow return Any
as you recommended? And I'd like to know if there is specific reason behind it.
from scala-js-dom.
In general, of course, we should be as precise as possible. But in the case of a callback returning Unit, it means more that you don't care what the result will be because you're not going to use it. I would agree with conveying the api's intent, in general. But for this user case, specifying Any helps the type inference to do the right thing. Scala APIs do the same: look at definitions of foreach
: they take functions returning a generic type U
(which, in contravariant position, is basically the same as Any
) instead of Unit
.
from scala-js-dom.
Thanks for the explanation. I suppose I better change my sources to confirm to this, if Scala API defines the signature of foreach in such a way.
from scala-js-dom.
Related Issues (20)
- `Location#origin` should return a `String` HOT 1
- Fetch `RequestInit` needs duplex attribute HOT 1
- Add `PageTransitionEvent` HOT 1
- Typo in "WriteableStream" trait name? HOT 1
- Recommended approach when `Response.type` is undefined? HOT 1
- `Element#id` returns undefined HOT 2
- Update available MIMEtypes HOT 5
- Use `XMLDocument` type when parsing XML string in `DOMParser` HOT 3
- Remove attributes class members from Node
- is changing `Array` -> `FrozenArray` binary compatible? HOT 4
- It looks we are missing some methods from the FormData class HOT 2
- Confusing type of ImageData.data HOT 3
- Create bindings for webgpu
- WebAudio classes
- LockOptions doesn't use val for fields, making overriding not possible HOT 2
- Constructor parameters for URLSearchParams are not quite right
- Clarify `enum` and `object literals` usage in `scalajs-dom`
- Return Type of HTMLCanvasElement getContext is not clear. HOT 1
- Support Int.Locale
- MediaQueryList.addListener has wrong type
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scala-js-dom.