From cc10f79de8a94cdc99f27defd2e5a888994ce00c Mon Sep 17 00:00:00 2001 From: nnivxix Date: Mon, 8 Apr 2024 09:39:48 +0700 Subject: [PATCH 1/7] wip: jsdoc on composable --- src/composables/useCollection.js | 47 +++++++++++++++++++--------- src/composables/useFormCollection.js | 14 ++++++++- src/composables/useFormTodo.js | 6 ++++ src/composables/useTodo.js | 25 ++++++--------- 4 files changed, 62 insertions(+), 30 deletions(-) diff --git a/src/composables/useCollection.js b/src/composables/useCollection.js index b9fa803..bc9f686 100644 --- a/src/composables/useCollection.js +++ b/src/composables/useCollection.js @@ -1,7 +1,17 @@ import { ref, toRaw, computed } from "vue"; import dbCollection from "@/repositories/db-collection"; +/** + * @typedef {Object} Collection + * @property {string} id + * @property {string} name + * @property {string} description + * @property {string | Date} created_at + * @property {import('@/composables/useFormTodo').FormTodo[]} todos + */ -const collections = ref([]); +/** + * @type {import('vue').Ref} + */ const collection = ref({ id: "", name: "", @@ -9,11 +19,19 @@ const collection = ref({ created_at: "", todos: [], }); +/** + * @type {import('vue').Ref} + */ +const collections = ref([]); + const useCollection = () => { const descriptionCollection = computed(() => { return collection.value?.description.replace(/(?:\r\n|\r|\n)/g, "
"); }); + /** + * @param {Collection} collection + */ const addCollection = (collection) => { collections.value.push(collection); @@ -22,24 +40,19 @@ const useCollection = () => { const getCollections = async () => { collections.value = await dbCollection.index(); }; + /** - * Detail Collection - * @returns {{ - * id: String, - * name: String, - * description: String, - * created_at: Date, - * todos: { - * name: String, - * priority: String, - * isDone: Boolean, - * created_at: Date, - * }[] - * }} collection + * + * @param {string} id + * @returns {Collection} */ const getDetailCollection = (id) => { return collections.value.find((collection) => collection.id == id); }; + + /** + * @param {string} id + */ const deleteColllection = (id) => { const index = collections.value.findIndex( (collection) => collection.id === id @@ -48,6 +61,12 @@ const useCollection = () => { collections.value.splice(index, 1); dbCollection.delete(id); }; + + /** + * + * @param {Collection} collection + * @returns {Collection} + */ const updateCollection = (collection) => { const index = collections.value.findIndex( (coll) => coll.id === collection.id diff --git a/src/composables/useFormCollection.js b/src/composables/useFormCollection.js index e768ef2..234dc7f 100644 --- a/src/composables/useFormCollection.js +++ b/src/composables/useFormCollection.js @@ -1,10 +1,19 @@ import { ref } from "vue"; import { customAlphabet } from "nanoid"; import useCollection from "@/composables/useCollection"; -import dbCollection from "@/repositories/db-collection"; const { addCollection, updateCollection } = useCollection(); +/** + * @typedef {Object} FormCollection + * @property {?string} id + * @property {string} name + * @property {string} description + * @property {import('@/composables/useFormTodo').Todo[]} todos + */ +/** + * @type {import('vue').Ref} + */ const collection = ref({ name: "", description: "", @@ -33,6 +42,9 @@ const useFormCollection = () => { } function addNewCollection() { const nanoid = customAlphabet("1234567890abcdef", 10); + /** + * @type {FormCollection} + */ const collection = { id: nanoid(), name: form.value.name, diff --git a/src/composables/useFormTodo.js b/src/composables/useFormTodo.js index 2bc5c42..30eb4ac 100644 --- a/src/composables/useFormTodo.js +++ b/src/composables/useFormTodo.js @@ -1,7 +1,13 @@ import { nanoid } from "nanoid"; import { ref } from "vue"; +/** + * @typedef {import('@/composables/useTodo').Todo} FormTodo + */ const isEditing = ref(false); +/** + * @type {import('vue').Ref} + */ const formTodo = ref({ id: `todo-${nanoid(7)}`, name: "", diff --git a/src/composables/useTodo.js b/src/composables/useTodo.js index f6fde86..e5066aa 100644 --- a/src/composables/useTodo.js +++ b/src/composables/useTodo.js @@ -1,6 +1,14 @@ import dbCollection from "@/repositories/db-collection"; import { toRaw, computed } from "vue"; import useCollection from "@/composables/useCollection"; +/** + * @typedef {Object} Todo + * @property {string} id + * @property {string} name + * @property {string} priority + * @property {string} isDone + * @property {Date} created_at + */ const { collection, getDetailCollection } = useCollection(); @@ -11,13 +19,7 @@ const useTodo = () => { ); /** * Add new todo to collection - * @param {{ - * id: string, - * name: string, - * priority: string, - * isDone: boolean, - * created_at: Date, - * }} todo + * @param {Todo} todo */ const addTodo = (todo) => { const { todos } = getDetailCollection(collection.value.id); @@ -47,13 +49,7 @@ const useTodo = () => { /** * Edit todo in collection - * @param {{ - * id: string, - * name: string, - * priority: string, - * isDone: boolean, - * created_at: Date, - * }} newTodo + * @param {Todo} newTodo */ const editTodo = (newTodo) => { const { todos } = getDetailCollection(collection.value.id); @@ -71,7 +67,6 @@ const useTodo = () => { /** * * @param {number} index - * @description still wip */ const deleteTodo = (index) => { const { todos } = getDetailCollection(collection.value.id); From e31d18945a4f735e79ed534ba5cf64bb6c1fede2 Mon Sep 17 00:00:00 2001 From: nnivxix Date: Mon, 8 Apr 2024 10:58:33 +0700 Subject: [PATCH 2/7] wip: jsdoc on component --- src/components/ExampleJson.vue | 1 + src/components/FormCollection.vue | 14 +++++++------- src/components/ProgressBar.vue | 11 +++++++++++ src/components/TodoItem.vue | 8 +++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/components/ExampleJson.vue b/src/components/ExampleJson.vue index 509b3c0..6f6f5bc 100644 --- a/src/components/ExampleJson.vue +++ b/src/components/ExampleJson.vue @@ -1,5 +1,6 @@ diff --git a/src/components/FormCollection.vue b/src/components/FormCollection.vue index 03c19e6..0b0c00f 100644 --- a/src/components/FormCollection.vue +++ b/src/components/FormCollection.vue @@ -1,13 +1,13 @@ From 70e9503a62780bede69257692ee51f6203470cfc Mon Sep 17 00:00:00 2001 From: nnivxix Date: Mon, 8 Apr 2024 14:35:22 +0700 Subject: [PATCH 7/7] refactor: jsdoc --- src/components/ExampleJson.vue | 2 +- src/components/FormCollection.vue | 10 ++------ src/components/ProgressBar.vue | 15 +++-------- src/components/TodoItem.vue | 7 +++--- src/composables/useCollection.js | 28 ++++++--------------- src/composables/useFormCollection.js | 16 ++++-------- src/composables/useFormTodo.js | 9 ++++--- src/composables/useTodo.js | 32 ++++++------------------ src/pages/collection/create.vue | 2 +- src/pages/collection/edit.vue | 2 +- src/pages/collection/id.vue | 9 +++++-- src/pages/import.vue | 4 +-- src/repositories/db-collection.js | 2 +- src/types.d.ts | 37 ++++++++++++++++++++++++++++ src/utils/export-collection.js | 2 +- src/utils/json-parser.js | 2 +- src/utils/validate-collection.js | 3 +-- 17 files changed, 87 insertions(+), 95 deletions(-) create mode 100644 src/types.d.ts diff --git a/src/components/ExampleJson.vue b/src/components/ExampleJson.vue index ac4090e..f4d7c90 100644 --- a/src/components/ExampleJson.vue +++ b/src/components/ExampleJson.vue @@ -1,5 +1,5 @@