Add initial project structure with backend and frontend setup
- Created backend structure with Go, including main application logic and API endpoints. - Added Docker support for both development and production environments. - Introduced frontend using Nuxt 3 with Tailwind CSS for styling. - Included configuration files for Docker and environment variables. - Established basic documentation for contributing, development, and deployment processes. - Set up .gitignore and .dockerignore files to manage ignored files in the repository.
This commit is contained in:
39
frontend-nuxt/lib/UniqueList.js
Normal file
39
frontend-nuxt/lib/UniqueList.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Elements should have unique field "id"
|
||||
*/
|
||||
export class UniqueList {
|
||||
constructor() {
|
||||
this.elements = {}
|
||||
}
|
||||
|
||||
update(dataList, addCallback, removeCallback, updateCallback) {
|
||||
const elementsToAdd = dataList.filter((it) => this.elements[it.id] === undefined)
|
||||
const elementsToRemove = Object.keys(this.elements)
|
||||
.filter((it) => dataList.find((up) => String(up.id) === it) === undefined)
|
||||
.map((id) => this.elements[id])
|
||||
if (removeCallback) {
|
||||
elementsToRemove.forEach((it) => removeCallback(it))
|
||||
}
|
||||
if (updateCallback) {
|
||||
dataList.forEach((newElement) => {
|
||||
const oldElement = this.elements[newElement.id]
|
||||
if (oldElement) {
|
||||
updateCallback(oldElement, newElement)
|
||||
}
|
||||
})
|
||||
}
|
||||
if (addCallback) {
|
||||
elementsToAdd.forEach((it) => addCallback(it))
|
||||
}
|
||||
elementsToRemove.forEach((it) => delete this.elements[it.id])
|
||||
elementsToAdd.forEach((it) => (this.elements[it.id] = it))
|
||||
}
|
||||
|
||||
getElements() {
|
||||
return Object.values(this.elements)
|
||||
}
|
||||
|
||||
byId(id) {
|
||||
return this.elements[id]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user