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:
Jeffrey Biles
2020-03-17 22:44:50 -07:00
parent 92c429407e
commit 48505b6002
3 changed files with 22 additions and 18 deletions

View File

@@ -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,
}
}