component_web_code.go 903 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //go:build js && wasm
  2. package ultraviolet
  3. import (
  4. "syscall/js"
  5. )
  6. type CodeComponentWeb struct {
  7. node js.Value
  8. view View
  9. change bool
  10. language string
  11. content string
  12. }
  13. func NewCodeComponentWeb(view View) *CodeComponentWeb {
  14. return &CodeComponentWeb{
  15. view: view,
  16. change: true,
  17. }
  18. }
  19. // Component
  20. func (this *CodeComponentWeb) Build(parent Component) {
  21. this.node = WebBuildCode(
  22. this.node,
  23. parent,
  24. this.view,
  25. this.language,
  26. this.content,
  27. )
  28. }
  29. func (this *CodeComponentWeb) Invalidate() bool {
  30. result := this.change
  31. this.change = false
  32. return result
  33. }
  34. func (this *CodeComponentWeb) Clean() {
  35. WebCleanChildren(this.node)
  36. this.change = true
  37. }
  38. // JS
  39. func (this *CodeComponentWeb) Node() js.Value {
  40. return this.node
  41. }
  42. // ComponentCode
  43. func (this *CodeComponentWeb) SetCode(language string, content string) {
  44. this.language = language
  45. this.content = content
  46. }