How to execute some init after element loaded to dom with Binding.scala

后端 未结 1 1789
闹比i
闹比i 2021-01-21 15:05
@dom 
def chart(show: Var[Boolean]) = {
  if(show.bind) {
    
  }
}

How can I init the canvas with some

相关标签:
1条回答
  • 2021-01-21 15:55

    Solution 1

    @dom 
    def chart(show: Var[Boolean]) = {
      if(show.bind) {
        val myCanvas = <canvas id="chartCanvas"><canvas>
        myInitializationCode(myCanvas)
        myCanvas
      } else {
        <!-- don't show canvas -->
      }
    }
    

    Solution 2

    You can create a custom SingleMountPoint, and put the initialization code in the overriden mount method:

    val yourCustomMountPoint = new SingleMountPoint[Boolean](show) {
      override def mount() = {
        super.mount()
        // Your custom initialization code
      }
      override def unmount() = {
        // Your custom clean up code
        super.unmount()
      }
      override def set(newValue: Boolean) = {
        // Your custom handler when `show` get changed
      }
    }
    
    // Inject your custom mount point into the rendering process
    yourCustomMountPoint.bind
    
    0 讨论(0)
提交回复
热议问题