@@ -107,40 +107,27 @@ export default defineComponent({
107107 const { errors } = useValidation ()
108108 const editingId = ref (0 )
109109 const addAuthor = async () => {
110- let newAuthors: AuthorType []
111110 const newAuthor: AuthorType = {}
112- if (authors .value === undefined ) {
113- newAuthors = [newAuthor ]
114- } else {
115- newAuthors = [... authors .value , newAuthor ]
116- }
111+ const newAuthors = [... authors .value , newAuthor ]
117112 setAuthors (newAuthors )
118113 editingId .value = newAuthors .length - 1
119114 // await the DOM update that resulted from updating the authors list
120115 await nextTick ()
121116 scrollToBottom ()
122117 }
123118 const removeAuthor = () => {
124- if (authors .value !== undefined ) {
125- const newAuthors = [... authors .value ]
126- newAuthors .splice (editingId .value , 1 )
127- setAuthors (newAuthors )
128- editingId .value = - 1
129- if (Array .isArray (newAuthors ) && newAuthors .length === 0 ) {
130- setAuthors ([])
131- }
132- }
119+ const newAuthors = [... authors .value ]
120+ newAuthors .splice (editingId .value , 1 )
121+ setAuthors (newAuthors )
122+ editingId .value = - 1
133123 }
134124 const setAuthorField = (field : keyof AuthorType , value : string ) => {
135- if (authors .value !== undefined ) {
136- const author = { ... authors .value [editingId .value ] }
137- author [field ] = value === ' ' ? undefined : value
138- authors .value [editingId .value ] = author
139- setAuthors (authors .value )
140- }
125+ const newAuthor = { ... authors .value [editingId .value ] }
126+ newAuthor [field ] = value === ' ' ? undefined : value
127+ authors .value [editingId .value ] = newAuthor
128+ setAuthors (authors .value )
141129 }
142130 const moveAuthorUp = (index : number ) => {
143- if (authors .value === undefined ) return
144131 moveUp (index , authors .value , setAuthors )
145132 if (editingId .value === index && index > 0 ) {
146133 editingId .value = editingId .value - 1
@@ -149,7 +136,6 @@ export default defineComponent({
149136 }
150137 }
151138 const moveAuthorDown = (index : number ) => {
152- if (authors .value === undefined ) return
153139 moveDown (index , authors .value , setAuthors )
154140 if (editingId .value === index && index < authors .value .length - 1 ) {
155141 editingId .value = editingId .value + 1
0 commit comments