0

The runNow method here has the documentation:

  /**
   * Executes this callback, on the current thread, right now, blocking until complete.
   *
   * In most cases, this type is passed to scalajs-react such that you don't need to call this method yourself.
   *
   * Exceptions will not be caught. Use [[attempt]] to catch thrown exceptions.
   */

This is a little bit vague and leads to four questions:

  1. when I am not supposed to call runNow() ? why ?
  2. is it so that the only situation when I should not (or don't have to) call runNow() is when I am using a Callback with ==> or --> (as described here) ? (my guess that this is true) or is there any other situation when runNow() is called for me by the framework ?
  3. when I am allowed to call runNow()? why ?
  4. why not just use runNow all the time ? would that cause any problems ? if yes, what ?

My current understanding is that it is ok (and even needed) to call runNow() from a scala-function that has been passed as a callback to a wrapped native JS react component. For example here.

I am not sure however.

Can someone clarify when it is OK and when it is not OK to call runNow() ?

1 Answer 1

1

I'll provide a more detailed answer tomorrow but first, have you read through the Callback docs? https://github.com/japgolly/scalajs-react/blob/master/doc/CALLBACK.md

5
  • Hmm, thanks for the answer, actually it seems that docs have been updated since I last read them ! So I have read only the old version. Need to read the new one and see how that answers the question.
    – jhegedus
    Mar 21, 2017 at 10:19
  • 1
    No worries. As the author, what I think is clear isn't so and it's a bit hard to know what's missing or confusing. Give me a shout if something's not making sense and/or feel free to PR any improvements.
    – Golly
    Mar 22, 2017 at 7:10
  • Golly, Could you please comment on this question ? It comes up again. I cannot find the answer in the doc. What I really don't understand is who is executing a Callback ? In the doc's it says : As is stressed above, "Callbacks are meant to be executed by React at a time and frequency of its choosing." When is this ? What does scala-js do with these callbacks ? How do they get executed in the end ?
    – jhegedus
    May 31, 2017 at 22:43
  • I mean, what is the corresponding concept (to Callbacks) in plain react ? I cannot really find it here : facebook.github.io/react/docs/hello-world.html Where do these Callbacks (in scalajs-react) come from ? Why do they even exist in scalajs-react ? In the react docs there is not much mention of callback - for example they cannot be found on the left side of the react document webpage). So why are they treated specially in scalajs-react (there is a long page of documentation dedicated to it : github.com/japgolly/scalajs-react/blob/master/doc/CALLBACK.md )?
    – jhegedus
    May 31, 2017 at 22:55
  • React has a concept of callbacks, it's just often implicit and hinted at in documentation like "don't call this at this point of time", "blah is only valid when blah". As React JS is untyped, scalajs-react is typed and so the callback concept and execution semantics separation is explicitly represented in Scala. Same story with Backends.
    – Golly
    Jun 12, 2017 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.