小编SeD*_*Dav的帖子

scala.js中真正的JS类来开发webcomponents

我想用scala.js在Polymer 2.0项目中开发一些web组件.虽然github上有一个很棒的演示项目,展示了它如何与Polymer 1.0一起工作.我不能得到类似于使用Polymer 2.0和原生元素注册技术的东西.

简单的外观可能如下所示

@ScalaJSDefined
class PolymerElement extends PolymerBase {
  def is: String = ""
  def properties: js.Dynamic = js.Dynamic.literal()
}

@js.native
@JSGlobal("Polymer.Element")
class PolymerBase extends HTMLElement
Run Code Online (Sandbox Code Playgroud)

实际元素:

@JSExportTopLevel("MyElement")
@ScalaJSDefined
class MyElement extends PolymerElement  {

   private var label = "init"

   override def is = "my-element"

   override def properties = js.Dynamic.literal(
    "label" -> Map(
      "type" -> "String",
      "value" -> "init",
      "notify" -> true
    ).toJSDictionary
  )

  def testMe = {
    println(label)
  }
}

object MyElement {
  @JSExportStatic …
Run Code Online (Sandbox Code Playgroud)

web-component polymer scala.js es6-class polymer-2.x

7
推荐指数
1
解决办法
318
查看次数