-1

I have a binding.scala component and a third party scalajs library that takes html string as input. How can the b.s component can be passed to the library method as an argument?

Specifics:

import com.thoughtworks.binding.Binding._
import com.thoughtworks.binding.{Binding, dom}

@dom def renderComponent: Binding[Element] = <h1> I am a component </h1>

def thirdPartyFunction(str: String) = {
  ...
}

I would like to call the function like thirdPartyFunction(renderComponent.bind.outerHtml.toString). However that call never gets executed.

I think this is related to some basic understanding with B.S up until now I have not faced with. Any suggestions?

2
  • Missing watch calls? Commented Nov 3, 2018 at 8:26
  • the thirdPartyFunction is invoked by a window event. Not through dom.render method though. Something like this, but how: window.onload = _ => thirdPartyFunction(renderComponent.bind.outerHtml.toString). Commented Nov 3, 2018 at 10:32

1 Answer 1

1

The answer is to wrap the .bind call with watch. For instance, in the window.onload function, something similar to the following:

   window.onload = _ => Binding{
       thirdPartyFunction(renderComponent.bind.outerHtml.toString)
   }.watch() 

Note that it is possible to initialize components without functions like window.onload. See this question How to execute some init after element loaded to dom with Binding.scala

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.