Created
February 11, 2020 09:15
-
-
Save kjk/e933c2e9cb52a6b5eed7226cff031b88 to your computer and use it in GitHub Desktop.
sumatra crash preview with alpine.js (made with https://codeeval.dev)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<httml> | |
<head> | |
<style> | |
html, body { | |
font-family: monospace; | |
font-size: 10pt; | |
} | |
</style> | |
<script> | |
const allCrashes = {{.Crashes}}; | |
function len(o) { | |
return o.length; | |
} | |
let crashesData = null; | |
/* | |
{ | |
days: [], | |
crashesByDay: {}, | |
}; | |
*/ | |
// returns [[CrahsInfo], [CrashInfo]] | |
function groupCrashesByDay() { | |
let crashesByDay = {}; | |
for (let crash of allCrashes) { | |
const day = crash.Day; | |
const a = crashesByDay[day] || []; | |
a.push(crash); | |
crashesByDay[day] = a; | |
} | |
let days = Object.keys(crashesByDay); | |
days.sort(); | |
days = days.reverse(); | |
let res = { | |
days: days, | |
crashesByDay: crashesByDay, | |
} | |
return res; | |
} | |
function getCrashesData() { | |
crashesData = crashesData || groupCrashesByDay(); | |
return crashesData; | |
} | |
function getCrashesByDay(day) { | |
return crashesData.crashesByDay[day]; | |
} | |
</script> | |
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v1.10.1/dist/alpine.js" defer></script> | |
</head> | |
<body> | |
<div x-data="getCrashesData()"> | |
<template x-for="day in days"> | |
<div> | |
<span x-text="day"></span> | |
<span x-text="len(crashesByDay[day])"></span> | |
<div x-data="{crashes: getCrashesByDay(day)}"> | |
</div> | |
</div> | |
</template> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment