1
0
mirror of https://github.com/morris/vanilla-todo.git synced 2025-08-11 00:24:10 +02:00

add some jsdoc comments

This commit is contained in:
Morris Brodersen
2023-12-03 11:34:36 +01:00
parent 8dc7bb1527
commit b236acc03f
2 changed files with 103 additions and 0 deletions

View File

@@ -176,6 +176,10 @@ Additionally, the global CSS namespace problem is unaddressed
(see e.g. [CSS Modules](https://github.com/css-modules/css-modules)). (see e.g. [CSS Modules](https://github.com/css-modules/css-modules)).
All JavaScript files are ES modules (`import`/`export`). All JavaScript files are ES modules (`import`/`export`).
I added a few
[JSDoc](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html)
comments to functions to get additional code completion in VSCode.
This helps, but using TypeScript would be much safer and less verbose.
Note that I've opted out of web components completely. Note that I've opted out of web components completely.
I can't clearly articulate what I find problematic about them I can't clearly articulate what I find problematic about them

View File

@@ -1,7 +1,38 @@
import { formatDateId } from './util.js'; import { formatDateId } from './util.js';
import { uuid } from './uuid.js'; import { uuid } from './uuid.js';
/**
* @typedef {{
* id: string;
* listId: string;
* index: number;
* label: string;
* done: boolean;
* }} TodoDataItem
*/
/**
* @typedef {{
* id: string;
* index: number;
* title: string;
* }} TodoDataCustomList
*/
/**
* @typedef {{
* items: TodoDataItem[];
* customLists: TodoDataCustomList[];
* at: string;
* customAt: number;
* }} TodoData
*/
export class TodoLogic { export class TodoLogic {
/**
* @param {Date} now
* @returns {TodoData}
*/
static initTodoData(now = new Date()) { static initTodoData(now = new Date()) {
return { return {
items: [], items: [],
@@ -35,6 +66,11 @@ export class TodoLogic {
.sort((a, b) => a.index - b.index); .sort((a, b) => a.index - b.index);
} }
/**
* @param {TodoData} data
* @param {{listId: string, label: string}} input
* @returns {TodoData}
*/
static addTodoItem(data, input) { static addTodoItem(data, input) {
let index = 0; let index = 0;
@@ -58,6 +94,11 @@ export class TodoLogic {
}; };
} }
/**
* @param {TodoData} data
* @param {{id: string, done: boolean}} input
* @returns {TodoData}
*/
static checkTodoItem(data, input) { static checkTodoItem(data, input) {
return { return {
...data, ...data,
@@ -67,6 +108,11 @@ export class TodoLogic {
}; };
} }
/**
* @param {TodoData} data
* @param {{id: string, label: string}} input
* @returns {TodoData}
*/
static editTodoItem(data, input) { static editTodoItem(data, input) {
return { return {
...data, ...data,
@@ -76,6 +122,11 @@ export class TodoLogic {
}; };
} }
/**
* @param {TodoData} data
* @param {{id: string, listId: string, index: number}} input
* @returns {TodoData}
*/
static moveTodoItem(data, input) { static moveTodoItem(data, input) {
const itemToMove = data.items.find((item) => item.id === input.id); const itemToMove = data.items.find((item) => item.id === input.id);
@@ -98,6 +149,11 @@ export class TodoLogic {
}; };
} }
/**
* @param {TodoData} data
* @param {{id: string}} input
* @returns {TodoData}
*/
static deleteTodoItem(data, input) { static deleteTodoItem(data, input) {
return { return {
...data, ...data,
@@ -118,6 +174,10 @@ export class TodoLogic {
.sort((a, b) => a.index - b.index); .sort((a, b) => a.index - b.index);
} }
/**
* @param {TodoData} data
* @returns {TodoData}
*/
static addCustomTodoList(data) { static addCustomTodoList(data) {
let index = 0; let index = 0;
@@ -138,6 +198,11 @@ export class TodoLogic {
}; };
} }
/**
* @param {TodoData} data
* @param {{id: string, title: string}} input
* @returns {TodoData}
*/
static editCustomTodoList(data, input) { static editCustomTodoList(data, input) {
return { return {
...data, ...data,
@@ -149,6 +214,11 @@ export class TodoLogic {
}; };
} }
/**
* @param {TodoData} data
* @param {{id: string, index: number}} input
* @returns {TodoData}
*/
static moveCustomTodoList(data, input) { static moveCustomTodoList(data, input) {
const customListToMove = data.customLists.find( const customListToMove = data.customLists.find(
(customList) => customList.id === input.id, (customList) => customList.id === input.id,
@@ -166,6 +236,11 @@ export class TodoLogic {
}; };
} }
/**
* @param {TodoData} data
* @param {{id: string}} input
* @returns {TodoData}
*/
static deleteCustomTodoList(data, input) { static deleteCustomTodoList(data, input) {
return { return {
...data, ...data,
@@ -177,6 +252,11 @@ export class TodoLogic {
// //
/**
* @param {TodoData} data
* @param {number} delta
* @returns {TodoData}
*/
static seekDays(data, delta) { static seekDays(data, delta) {
const t = new Date(`${data.at}T00:00:00`); const t = new Date(`${data.at}T00:00:00`);
t.setDate(t.getDate() + delta); t.setDate(t.getDate() + delta);
@@ -184,14 +264,28 @@ export class TodoLogic {
return { ...data, at: formatDateId(t) }; return { ...data, at: formatDateId(t) };
} }
/**
* @param {TodoData} data
* @returns {TodoData}
*/
static seekToToday(data) { static seekToToday(data) {
return { ...data, at: formatDateId(new Date()) }; return { ...data, at: formatDateId(new Date()) };
} }
/**
* @param {TodoData} data
* @param {Date} date
* @returns {TodoData}
*/
static seekToDate(data, date) { static seekToDate(data, date) {
return { ...data, at: formatDateId(date) }; return { ...data, at: formatDateId(date) };
} }
/**
* @param {TodoData} data
* @param {number} delta
* @returns {TodoData}
*/
static seekCustomTodoLists(data, delta) { static seekCustomTodoLists(data, delta) {
return { return {
...data, ...data,
@@ -204,6 +298,11 @@ export class TodoLogic {
// //
/**
* @template {{index?: number}} T
* @param {T[]} array
* @returns {T[]}
*/
static setIndexes(array) { static setIndexes(array) {
return array.map((item, index) => return array.map((item, index) =>
item.index === index ? item : { ...item, index }, item.index === index ? item : { ...item, index },