Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bau-0.90 #1774

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frameworks/non-keyed/bau/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link href="/css/currentStyle.css" rel="stylesheet" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bau.js Benchmark</title>
<title>Bau.js Non Keyed Benchmark</title>
</head>
<body>
<div id="app"></div>
Expand Down
74 changes: 30 additions & 44 deletions frameworks/non-keyed/bau/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,7 @@ const A = [
"expensive",
"fancy",
];
const C = [
"red",
"yellow",
"blue",
"green",
"pink",
"brown",
"purple",
"brown",
"white",
"black",
"orange",
];
const C = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"];
const N = [
"table",
"chair",
Expand All @@ -64,10 +52,7 @@ const N = [

let nextId = 1;

const buildLabel = () =>
bau.state(
`${A[random(A.length)]} ${C[random(C.length)]} ${N[random(N.length)]}`
);
const buildLabel = () => bau.state(`${A[random(A.length)]} ${C[random(C.length)]} ${N[random(N.length)]}`);

const buildData = (count) => {
const data = new Array(count);
Expand All @@ -83,16 +68,16 @@ const buildData = (count) => {
};

const dataState = bau.state([]);
const selectedState = bau.state(0);
let selectedRow = null;

const run = () => {
dataState.val = buildData(1000);
selectedState.val = 0;
selectedRow = null;
};

const runLots = () => {
dataState.val = buildData(10000);
selectedState.val = 0;
selectedRow = null;
};

const add = () => {
Expand All @@ -118,55 +103,56 @@ const swapRows = () => {

const clear = () => {
dataState.val = [];
selectedState.val = 0;
selectedRow = null;
};

const remove = ({ id, event }) => {
const remove = (id) => () => {
const idx = dataState.val.findIndex((d) => d.id === id);
if (idx > -1) {
dataState.val.splice(idx, 1);
}
};

const select = ({ id, event }) => {
selectedState.val = id;
const selectRow = (event) => {
if (selectedRow) {
selectedRow.className = "";
}
selectedRow = event.target.parentNode.parentNode;
selectedRow.className = "danger";
};

const Row = ({ id, label }) =>
tr(
const Row = ({ id, label }) => {
const tdIdEl = td({ class: "col-md-1" }, id);
const aLabelEl = a({ onclick: selectRow }, label);
const aRemove = a({ onclick: remove(id) }, span({ class: "glyphicon glyphicon-remove", "aria-hidden": true }));

return tr(
{
class: () => (selectedState.val == id ? "danger" : ""),
bauUpdate: (element, data) => {
tdIdEl.textContent = data.id;
aLabelEl.replaceWith(a({ onclick: selectRow }, data.label));
aRemove.onclick = remove(data.id);
},
},
td({ class: "col-md-1" }, id),
td(
{ class: "col-md-4" },
a({ onclick: (event) => select({ id, event }) }, label)
),
td(
{ class: "col-md-1" },
a(
{ onclick: (event) => remove({ id, event }) },
span({ class: "glyphicon glyphicon-remove", "aria-hidden": true })
)
),
tdIdEl,
td({ class: "col-md-4" }, aLabelEl),
td({ class: "col-md-1" }, aRemove),
td({ class: "col-md-6" })
);
};

const Button = ({ id, title, onclick }) =>
div(
{ class: "col-sm-6 smallpad" },
button(
{ type: "button", class: "btn btn-primary btn-block", id, onclick },
title
)
button({ type: "button", class: "btn btn-primary btn-block", id, onclick }, title)
);

const Jumbotron = ({}) =>
div(
{ class: "jumbotron" },
div(
{ class: "row" },
div({ class: "col-md-6" }, h1("Bau Benchmark")),
div({ class: "col-md-6" }, h1("Bau Non-Keyed Benchmark")),
div(
{ class: "col-md-6" },
div(
Expand Down
Loading