/docs/examples/uibench.html

https://github.com/thysultan/dio.js · HTML · 112 lines · 90 code · 22 blank · 0 comment · 0 complexity · 8dad0aacee5071e81b19f3d3f563788f MD5 · raw file

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset=utf-8>
  5. <meta http-equiv=x-ua-compatible content=ie=edge>
  6. <meta name=viewport content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  7. <title>UIBench</title>
  8. <script src=https://unpkg.com/dyo></script>
  9. <script src=https://localvoid.github.io/uibench-base/0.1.0/uibench.js></script>
  10. <link rel=stylesheet href=https://localvoid.github.io/uibench-base/0.1.0/styles.css>
  11. </head>
  12. <body>
  13. <main></main>
  14. <script>
  15. const {h, memo, render} = dyo
  16. const target = document.querySelector('main')
  17. const TableCell = memo(({text}) => {
  18. return h('td', {className: 'TableCell', onClick: (event, {text}) => {
  19. console.log('Clicked' + text)
  20. event.stopPropagation()
  21. }}, text)
  22. }, (prev, next) => prev.text === next.text)
  23. const TableRow = memo (({data}) => {
  24. const classes = data.active ? 'TableRow active' : 'TableRow'
  25. const cells = data.props
  26. const length = cells.length
  27. const children = []
  28. for (var i = 0; i < length; i++) {
  29. children[i] = h(TableCell, {key: i, text: cells[i]})
  30. }
  31. return h('tr', {className: classes, 'data-id': data.id}, h(TableCell, {text: '#' + data.id}), children)
  32. }, (prev, next) => prev.data === next.data)
  33. const Table = memo(({data}) => {
  34. const {items} = data
  35. const {length} = items
  36. const children = []
  37. for (var i = 0; i < length; i = i + 1) {
  38. const item = items[i]
  39. children[i] = h(TableRow, {key: item.id, data: item})
  40. }
  41. return h('table', {className: 'Table'}, h('tbody', {}, children))
  42. }, (prev, next) => prev.data === next.data)
  43. const AnimBox = memo(({data}) => {
  44. const {time} = data
  45. const style = 'border-radius:'+(time % 10)+'px;background:rgba(0,0,0,'+(0.5 + ((time % 10) / 10))+')'
  46. return h('div', {className: 'AnimBox', 'data-id': data.id, style: style})
  47. }, (prev, next) => prev.data === next.data)
  48. const Anim = memo(({data}) => {
  49. const {items} = data
  50. const {length} = items
  51. const children = []
  52. for (var i = 0; i < length; i = i + 1) {
  53. const item = items[i]
  54. children[i] = h(AnimBox, {key: item.id, data: item})
  55. }
  56. return h('div', {className: 'Anim'}, children)
  57. }, (prev, next) => prev.data === next.data)
  58. const TreeLeaf = memo(({data}) => {
  59. return h('li', {className: 'TreeLeaf'}, data.id);
  60. }, (prev, next) => prev.data === next.data)
  61. const TreeNode = memo(({data}) => {
  62. const {length} = data.children
  63. const children = []
  64. for (let i = 0; i < length; i++) {
  65. const n = data.children[i]
  66. children[i] = h(n.container ? TreeNode : TreeLeaf, {key: n.id, data: n})
  67. }
  68. return h('ul', {className: 'TreeNode'}, children)
  69. }, (prev, next) => prev.data === next.data)
  70. const Tree = memo(({data}) => {
  71. return h('div', {className: 'Tree'},
  72. h(TreeNode, {data: data.root})
  73. )
  74. }, (prev, next) => prev.data === next.data)
  75. const Main = memo(({data}) => {
  76. const {location} = data
  77. const props = {data: data[location]}
  78. const section = h(location === 'table' ? Table : location === 'anim' ? Anim : Tree, props)
  79. return h('div', {className: 'Main'}, section)
  80. }, (prev, next) => prev.data === next.data)
  81. uibench.init('Dyo')
  82. document.addEventListener('DOMContentLoaded', () => {
  83. uibench.run(
  84. data => render(h(Main, {data}), target),
  85. data => render(h('pre', {}, JSON.stringify(data, null, 2)), target)
  86. )
  87. })
  88. </script>
  89. </body>
  90. </html>