Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import { createComponent, Component, fdValue, bootstrap, fdFor, fdIf, fdObject } from 'faster-dom';
  2.  
  3. class Comp extends Component {
  4. reactive = {
  5. show: fdIf(true),
  6. text: fdValue("Here timer")
  7. }
  8.  
  9. get show() {
  10. return this.reactive.show;
  11. }
  12.  
  13. get text() {
  14. return this.reactive.text
  15. }
  16.  
  17. onClick = () => {
  18. this.show.value = !this.show.value;
  19. this.text.value = this.show.value ? "Here timer" : "Sorry not timer"
  20. }
  21.  
  22. template = {
  23. tag: "div",
  24. children: [
  25. {
  26. tag: "p",
  27. children: [
  28. {
  29. tag: "span",
  30. textValue: "Current value:"
  31. },
  32. {
  33. tag: "span",
  34. textValue: this.show
  35. },
  36. ]
  37. },
  38. {
  39. tag: "button",
  40. listeners: {
  41. click: this.onClick,
  42. },
  43. textValue: "Change state"
  44. },
  45. {
  46. tag: "div",
  47. textValue: "You will see me always"
  48. },
  49. {
  50. tag: "div",
  51. show: this.show,
  52. textValue: "You will sometimes"
  53. }, {
  54. tag: "div",
  55. children: [
  56. {
  57. tag: "strong",
  58. textValue: this.text
  59. },
  60. ]
  61. }
  62. ]
  63. }
  64. }
  65.  
  66. function createComp() {
  67. return createComponent(Comp)
  68. }
  69.  
  70.  
  71. bootstrap('#app', createComp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement