Skip to content
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

More complete code example #79

Closed
phdoerfler opened this issue Apr 4, 2022 · 1 comment
Closed

More complete code example #79

phdoerfler opened this issue Apr 4, 2022 · 1 comment

Comments

@phdoerfler
Copy link

phdoerfler commented Apr 4, 2022

Let's pretend for the sake of this issue, I'm an impatient ninja coder who can't be bothered to read any documentation.

<impatient ninja coder>
I copy paste the sbt libraryDependencies line, then the code example. I doesn't compile. What imports am I missing?
Because I'm a hipster dev who lives on #twitter and stack overflow, I use VS Code as "IDE" which is of no help. I start looking for tests. Where are they? I move on to the javadocs. Hosted javadocs, great! But… what is this? jsdom and generic? builders, codecs, defs? What do I import now? I randomly import both jsdom._ and generic._ to no avail.
I am left with this:

org.scalajs.dom.html.Div does not take parameters
       val meow = div(
                     ^

I give up, because I am impatient and just wanted to save time in the first place and I don't want to go down yet another rabbit hole.
</impatient ninja coder>

@phdoerfler phdoerfler changed the title Add imports to code example More complete code example Apr 4, 2022
@raquo
Copy link
Owner

raquo commented Apr 4, 2022

Hello mr impatient ninja coder :)

If you are trying to use Scala DOM Types as an end user, you probably want to use Laminar instead (which uses this library under the hood). Add "com.raquo" %%% "laminar" % "0.14.2" to sbt libraryDependencies, and see the complete Hello world example (or just go straight to running laminar-examples locally). This section of the docs elaborates more on imports – it's generally just one line and you don't need to import anything from Scala DOM Types directly.

As is mentioned in the docs, Scala DOM Types itself does not actually offer the div(attr := value) syntax, it is a low level library designed for other libraries to use, so it is up to the consuming library (such as Laminar) to implement such syntax. If you are trying to build your own library based on Scala DOM Types, then look at how Laminar uses Scala DOM Types internally, starting with the Laminar.scala file. Detailed documentation on that is missing due to lack of time and availability of several example implementations (Laminar, Outwatch, ff4s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants