2016-09-25 5 views
1

scalatags.Text.all._scalatags.JsDom.all._ 패키지의 차이점은 무엇입니까?scalatags JsDom vs 텍스트

official scalatags tutorial에서 당신은 읽을 수

// import scalatags.Text.all._ 
// OR 
// import scalatags.JsDom.all._ 
html(
    head(
    script(src:="..."), 
    script(
     "alert('Hello World')" 
    ) 
), 
    body(
    div(
     h1(id:="title", "This is a title"), 
     p("This is a big paragraph of text") 
    ) 
) 
) 
And turns them into HTML like this: 

<html> 
    <head> 
     <script src="..."></script> 
     <script>alert('Hello World')</script> 
    </head> 
    <body> 
     <div> 
      <h1 id="title">This is a title</h1> 
      <p>This is a big paragraph of text</p> 
     </div> 
    </body> 
</html> 

답변

2

차이는 부품 DOMBackendInternals에 scalatags 설명서에 설명되어 있습니다.

shortucts에서

scalatags.Text 패키지를 사용하여, 구조 String 직접 렌더링되지만 scalatags.JsDOM 패키지를 사용하는 경우, 구조 org.scalajs.dom.raw.Element의 아형에 렌더링 (외부 scalatags의 - 그것은 scalajs 라이브러리의 일부이다). Element을 다룰 때 manipulate dom structure very low level of abstraction을 추가로 처리 할 수 ​​있습니다. 여기

, scalatags.Text.를 사용하여, h1String에 렌더링 : 여기

import scalatags.Text.all._ 
    val x: String = h1("some header").render 
    //x is a String 

하지만를 scalatags.JsDom를 사용하는 경우, h1org.scalajs.dom.raw.HTMLHeadingElement에 렌더링 :

import scalatags.JsDom.all._ 

    val x: Heading = h1("some header").render 
    //x is type of Heading, which is defined as: 
    //type Heading = raw.HTMLHeadingElement 
    //raw.HTMLHeadingElement is org.scalajs.dom.raw.HTMLHeadingElement