mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-17 21:24:59 +00:00
Two refactors: one to make it reactive, the other to make it work
The one that made it work was storing `ids` outside of the useEmailSelection function. That makes it shared between the multiple uses of the useEmailSelection function.
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
import { ref } from 'vue';
|
||||
import { ref, reactive } from 'vue';
|
||||
|
||||
let ids = new Set(['1', '5']);
|
||||
export const useEmailSelection = function(){
|
||||
let selectedEmailIds = ref(new Set(['1', '5']))
|
||||
|
||||
let toggleEmailSelection = (id) => {
|
||||
if(selectedEmailIds.value.has(id)) {
|
||||
selectedEmailIds.value.delete(id)
|
||||
} else {
|
||||
selectedEmailIds.value.add(id);
|
||||
let emailSelection = reactive({
|
||||
ids: ids,
|
||||
toggle: function(id) {
|
||||
if(this.ids.has(id)) {
|
||||
this.ids.delete(id)
|
||||
} else {
|
||||
this.ids.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
selectedEmailIds,
|
||||
toggleEmailSelection
|
||||
emailSelection,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user