Skip to content

Commit

Permalink
Merge branch 'master' of github.com:krausest/js-framework-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
krausest committed Dec 31, 2022
2 parents bb3f002 + 9e82910 commit 51828ed
Show file tree
Hide file tree
Showing 12 changed files with 539 additions and 0 deletions.
54 changes: 54 additions & 0 deletions frameworks/keyed/doohtml/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DooHTML</title>
<link href="/css/currentStyle.css" rel="preload" as="style"/>
<link href="/css/currentStyle.css" rel="stylesheet"/>
<link href="./js/doo.html.min.js" rel="preload" as="script"/>
<script src="./js/doo.html.min.js"></script>
<script type="module" src="./js/Main.class.js" defer ></script>
</head>
<body>
<div id="main">
<div class="container">
<div class="jumbotron">
<div class="row">
<div class="col-md-6">
<h1>DooHTML - keyed</h1><span class="ver"></span>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="run">Create 1,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="runlots">Create 10,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="add">Append 1,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="update">Update every 10th row</button>
</div>
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="clear">Clear</button>
</div>
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="swaprows">Swap Rows</button>
</div>
</div>
</div>
</div>
</div>
<doo-main
context="shadow"
link="/css/currentStyle.css"
bind="rows"
template="./templates/main.html"
></doo-main>
</div>
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
</div>
</body>
</html>
172 changes: 172 additions & 0 deletions frameworks/keyed/doohtml/js/Main.class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
'use strict'

const _random = max => Math.random() * max | 0

const adjectives = ["pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean", "elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive", "cheap", "expensive", "fancy"]
const colours = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"]
const nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"]

const lenA = adjectives.length, lenB = colours.length, lenC = nouns.length

Doo.define(
class Main extends Doo {
constructor() {
super(100)
this.scrollTarget = '.table'
this.defaultDataSet = 'rows'
this.ID = 1
this.data = {
[this.defaultDataSet]: []
}
this.add = this.add.bind(this)
this.run = this.run.bind(this)
this.runLots = this.runLots.bind(this)
this.update = this.update.bind(this)
this.clear = this.clear.bind(this)
this.swaprows = this.swapRows.bind(this)
this.addEventListeners()
this.selectedRow = undefined
document.querySelector(".ver").innerHTML += ` ${Doo.version} (keyed)`
document.title += ` ${Doo.version} (keyed)`
}

async dooAfterRender() {
this.tbody = this.shadow.querySelector('#tbody')
this.shadow.querySelector(this.scrollTarget).addEventListener('click', e => {
e.preventDefault()
if (e.target.parentElement.matches('.remove')) {
this.delete(e.target.parentElement)
} else if (e.target.tagName === 'A') {
this.select(e.target)
}
})
}

getParentRow(elem) {
while (elem) {
if (elem.tagName === "TR") {return elem}
elem = elem.parentNode
}
return undefined
}

buildData(count = 1000) {
const data = []
for (let i = 0; i < count; i++) {
data.push({id: this.ID++,label: adjectives[_random(lenA)] + " " + colours[_random(lenB)] + " " + nouns[_random(lenC)]})
}
return data
}

getIndex(row) {
let idx = this.data.rows.findIndex((item, i) => {
if (item.id === row.key) {
return i
}
})
return idx
}

getIndex(row) {
let idx = this.data.rows.findIndex((item, i) => {
if (item.id === row.key) {
return i
}
})
return idx
}

delete(elem) {
let row = this.getParentRow(elem)
if (row) {
let idx = this.getIndex(row)
this.tbody.removeChild(row)
if (idx !== undefined) {
this.data.rows.splice(idx,1)
}
}
}

run() {
this.clear()
this.data.rows = this.buildData()
this.renderTable()
}

add() {
let start = this.data.rows.length
this.data.rows = this.data.rows.concat(this.buildData())
this.append(this.data.rows, this.tbody, start)
}

runLots() {
this.clear()
this.data.rows = this.buildData(10000)
this.renderTable()
}

update() {
for (let i=0, len = this.data.rows.length;i<len;i+=10) {
this.tbody.childNodes[i].childNodes[1].childNodes[0].innerText = this.data.rows[i].label += ' !!!'
}
}

select(elem) {
if (this.selectedRow) {
this.selectedRow.classList.remove('danger')
this.selectedRow = undefined
}
this.toggleSelect(this.getParentRow(elem))
}

toggleSelect(elem) {
let row = this.getParentRow(elem)
if (row) {
row.classList.toggle('danger')
if (row.classList.contains('danger')) {
this.selectedRow = row
}
}
}

clear() {
this.data.rows = []
this.tbody.textContent = ''
}

swapRows() {
if (this.data.rows.length > 998) {
let node1 = this.tbody.firstChild.nextSibling,
node2 = node1.nextSibling,
node998 = this.tbody.childNodes[998],
node999 = node998.nextSibling,
row1 = this.data.rows[1]

this.data.rows[1] = this.data.rows[998];
this.data.rows[998] = row1

this.tbody.insertBefore(node998, node2)
this.tbody.insertBefore(node1, node999)
}
}

addEventListeners() {
document.getElementById("main").addEventListener('click', e => {
e.preventDefault()
if (e.target.matches('#runlots')) {
this.runLots()
} else if (e.target.matches('#run')) {
this.run()
} else if (e.target.matches('#add')) {
this.add()
} else if (e.target.matches('#update')) {
this.update()
} else if (e.target.matches('#clear')) {
this.clear()
} else if (e.target.matches('#swaprows')) {
this.swapRows()
}
})
}
}
)
2 changes: 2 additions & 0 deletions frameworks/keyed/doohtml/js/doo.html.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions frameworks/keyed/doohtml/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions frameworks/keyed/doohtml/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "js-framework-benchmark-doohtml",
"version": "0.80.2",
"description": "DooHTML JS-Benchmark",
"main": "Main.class.js",
"js-framework-benchmark": {
"frameworkVersion": "",
"frameworkHomeURL": "https://doohtml.com",
"useShadowRoot": true,
"shadowRootName": "doo-main",
"buttonsInShadowRoot": false,
"issues": [772, 1139]
},
"scripts": {
"build-dev": "exit 0",
"build-prod": "exit 0"
},
"keywords": [],
"author": "Henrik Javen",
"license": "Apache-2.0",
"homepage": "https://doohtml.com",
"repository": {
"type": "git",
"url": "https://github.com/hman61/js-framework-benchmark"
}
}

7 changes: 7 additions & 0 deletions frameworks/keyed/doohtml/templates/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<template>
<table class="table table-hover table-striped test-data">
<link href="${link}" rel="stylesheet">
<tbody id="tbody"><tr bind="rows"><td class="col-md-1">{{id}}</td><td class="col-md-4"><a>{{label}}</a></td><td class="col-md-1"><a class="remove"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr></tbody>
</table>
</template>
54 changes: 54 additions & 0 deletions frameworks/non-keyed/doohtml/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DooHTML</title>
<link href="/css/currentStyle.css" rel="preload" as="style"/>
<link href="/css/currentStyle.css" rel="stylesheet"/>
<link href="./js/doo.html.min.js" rel="preload" as="script"/>
<script src="./js/doo.html.min.js"></script>
<script type="module" src="./js/Main.class.js" defer ></script>
</head>
<body>
<div id="main">
<div class="container">
<div class="jumbotron">
<div class="row">
<div class="col-md-6">
<h1>DooHTML - non-keyed</h1><span class="ver"></span>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="run">Create 1,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="runlots">Create 10,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="add">Append 1,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="update">Update every 10th row</button>
</div>
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="clear">Clear</button>
</div>
<div class="col-sm-6 smallpad">
<button type="button" class="btn btn-primary btn-block" id="swaprows">Swap Rows</button>
</div>
</div>
</div>
</div>
</div>
<doo-main
context="shadow"
link="/css/currentStyle.css"
bind="rows"
template="./templates/main.html"
></doo-main>
</div>
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
</div>
</body>
</html>
Loading

0 comments on commit 51828ed

Please sign in to comment.