Skip to content

Commit

Permalink
Use refs instead of computed to preserve the relations
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb committed Aug 15, 2022
1 parent 8db6aba commit fc3e795
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/stores/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ export const useResume = defineStore('resume', () => {
const bio = computed(() => resume.value?.bio)

// Parse creations data from JSON.
const idEpicMap = ref<Record<string, Epic>>({})
const epics = computed<Epic[]>(() => {
const epics = ref<Epic[]>([])
const populateEpics = () => {
const creations = resume.value?.creations ?? []
return creations.map((epicJson) => {
creations.forEach((epicJson) => {
const epic = new Epic(epicJson)
idEpicMap.value[epicJson.id] = epic
return epic
epics.value.push(epic)
})
})
}

// Parse role data from JSON.
const orgs = computed<Org[]>(() => {
const orgs = ref<Org[]>([])
const populateOrgs = () => {
const work = resume.value?.work ?? []
return work.map((orgJson) => new Org(orgJson))
})

const initResume = (data: Resume) => {
resume.value = data
work.forEach((orgJson) => {
const org = new Org(orgJson)
orgs.value.push(org)
})
}

const mapRelations = () => {
// Establish role-epic associations.
orgs.value.forEach((org) => {
org.roles.forEach((role) => {
Expand All @@ -47,6 +48,13 @@ export const useResume = defineStore('resume', () => {
})
}

const initResume = (data: Resume) => {
resume.value = data
populateEpics()
populateOrgs()
mapRelations()
}

const loadResume = async (url: string) => {
const response = await axios.get(url)
initResume(response.data)
Expand Down

1 comment on commit fc3e795

@vercel
Copy link

@vercel vercel bot commented on fc3e795 Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.