Giter VIP home page Giter VIP logo

Comments (5)

l15k4 avatar l15k4 commented on August 16, 2024

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.

sjrd avatar sjrd commented on August 16, 2024

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.

mysticfall avatar mysticfall commented on August 16, 2024

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.

sjrd avatar sjrd commented on August 16, 2024

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.

mysticfall avatar mysticfall commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.