Skip to content

Commit

Permalink
Migrate contacts store (no usages..?)
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory V <[email protected]>
  • Loading branch information
GVodyanov committed Jan 28, 2024
1 parent 3628368 commit 73caffa
Showing 1 changed file with 43 additions and 49 deletions.
92 changes: 43 additions & 49 deletions src/store/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,54 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import Vue from 'vue'
import { defineStore } from 'pinia'

const state = {
contacts: [],
contactByEMail: {},
}

const mutations = {

/**
* Append a single contact to the store
*
* @param {object} state The store data
* @param {object} data The destructuring object
* @param {object} data.contact The contact to append to the store
*/
appendContact(state, { contact }) {
if (state.contacts.indexOf(contact) === -1) {
state.contacts.push(contact)
export default defineStore('contacts', {
state: () => {
return {
contacts: [],
contactByEmail: {},
}
},
actions: {
/**
* Append a single contact to the store
*
* @param {object} data The destructuring object
* @param {object} data.contact The contact to append to the store
*/
appendContact({ contact }) {
if (this.contacts.indexOf(contact) === -1) {
this.contacts.push(contact)
}

for (const email of contact.emails) {
// In the unlikely case that multiple contacts
// share the same email address, we will just follow
// first come, first served.
if (state.contactByEMail[email] === undefined) {
Vue.set(state.contactByEMail, email, contact)
for (const email of contact.emails) {
// In the unlikely case that multiple contacts
// share the same email address, we will just follow
// first come, first served.
if (this.contactByEmail[email] === undefined) {
this.contactByEmail[email] = contact
}
}
}
},
},

/**
* Removes a single contact from the store
*
* @param {object} state The store data
* @param {object} data The destructuring object
* @param {object} data.contact The contact to remove from the store
*/
removeContact(state, { contact }) {
for (const email of contact.emails) {
if (state.contactByEMail[email] === contact) {
Vue.delete(state.contactByEMail, email)
/**
* Removes a single contact from the store
*
* @param {object} data The destructuring object
* @param {object} data.contact The contact to remove from the store
*/
removeContact({ contact }) {
for (const email of contact.emails) {
if (this.contactByEmail[email] === contact) {
this.contactByEmail.delete(email)
}
}
}

const index = state.contacts.indexOf(contact)
if (index !== -1) {
state.contacts.splice(index, 1)
}
const index = this.contacts.indexOf(contact)
if (index !== -1) {
this.contacts.splice(index, 1)
}
},
},
}

const getters = {}

const actions = {}

export default { state, mutations, getters, actions }
})

0 comments on commit 73caffa

Please sign in to comment.