mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-18 05:25:08 +00:00
Abstract useEmailSelection into separate function
This commit is contained in:
@@ -23,17 +23,11 @@
|
||||
|
||||
<script>
|
||||
import { format } from 'date-fns'
|
||||
import { ref } from 'vue';
|
||||
import useEmailSelection from '../composition/useEmailSelection';
|
||||
|
||||
export default {
|
||||
setup(){
|
||||
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 {selectedEmailIds, toggleEmailSelection} = useEmailSelection();
|
||||
return {format, selectedEmailIds, toggleEmailSelection}
|
||||
},
|
||||
props: {
|
||||
|
||||
19
src/composition/useEmailSelection.js
Normal file
19
src/composition/useEmailSelection.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
selectedEmailIds,
|
||||
toggleEmailSelection
|
||||
}
|
||||
}
|
||||
|
||||
export default useEmailSelection;
|
||||
Reference in New Issue
Block a user