feature/projects-all-the-way-down #3323

Merged
konrad merged 123 commits from feature/projects-all-the-way-down into main 2023-05-30 10:09:40 +00:00
2 changed files with 3 additions and 1 deletions
Showing only changes of commit a95014dc5d - Show all commits

View File

@ -29,6 +29,7 @@ export const useProjectStore = defineStore('project', () => {
// The projects are stored as an object which has the project ids as keys.
const projects = ref<ProjectState>({})
const projectsArray = computed(() => Object.values(projects.value))
const hasProjects = computed(() => projects.value ? true : false)
const getProjectById = computed(() => {
return (id: IProject['id']) => typeof projects.value[id] !== 'undefined' ? projects.value[id] : null
@ -181,6 +182,7 @@ export const useProjectStore = defineStore('project', () => {
isLoading: readonly(isLoading),
projects: readonly(projects),
projectsArray: readonly(projectsArray),
hasProjects: readonly(hasProjects),
getProjectById,
findProjectByExactname,

View File

@ -80,7 +80,7 @@ const projectHistory = computed(() => {
const migratorsEnabled = computed(() => configStore.availableMigrators?.length > 0)
const hasTasks = computed(() => baseStore.hasTasks)
const hasProjects = computed(() => projectStore.projects ? true : false)
const hasProjects = computed(() => projectStore.hasProjects)
konrad marked this conversation as resolved Outdated

This should be a computed of the store, like hasTasks.
Shouldn't we check the length here (projectStore.projects?.length)?

This should be a computed of the store, like `hasTasks`. Shouldn't we check the length here (`projectStore.projects?.length`)?

projects is an object, so checking the length of it won't work.

`projects` is an object, so checking the length of it won't work.

Moved it to the store.

Moved it to the store.

Then Object.keys?.length

Then `Object.keys?.length`

Then Object.keys?.length

Wouldn't that cause a call to Object.keys? I think my solution is faster.

> Then `Object.keys?.length` Wouldn't that cause a call to `Object.keys`? I think my solution is faster.

Checked it: https://jsbench.me/hslfseq93y/1

Using Object.keys really is slower, and by a lot.

Checked it: https://jsbench.me/hslfseq93y/1 Using `Object.keys` really is slower, and by a lot.

True. Using a Map with size would probably be the perfect solution here. But that is something for another time.

True. Using a Map with size would probably be the perfect solution here. But that is something for another time.

Don't wrap computed in computed. use projectStore.hasProjects directly

Don't wrap computed in computed. use `projectStore.hasProjects` directly

Done

Done
const loading = computed(() => taskStore.isLoading)
const deletionScheduledAt = computed(() => parseDateOrNull(authStore.info?.deletionScheduledAt))