ko9x / my-notes-beta

An app to make it easier for me to see my coding notes
0 stars 0 forks source link

Fix the deleted notes not being removed from the DOM instantly. Requires a refresh #7

Closed ko9x closed 7 years ago

ko9x commented 7 years ago

The problem is that an array is created in the list item component. So the note is being deleted from the database just fine, but the item is not being removed from the array. The options I thought of initially are using an event listener to pass the object key to the list component from the item component and then add a function to the list component that uses the key to remove it from the array. Or I could move the whole function that created the array to the service and then use a subscribe to watch for changes to the array. The pros to that are, the array needs to be accessed by multiple components (navbar and list component are the two that come to mind) so it would make sense to move it to the noteService. The issue there though is that there is no OnInit function in the service so I would need to add it to the constructor. But I am pretty sure that is not a best preactice.

ko9x commented 7 years ago

Fixed. This was the method used onDelete(note: Note) { this.currentPageSections.forEach(array => { array.splice(array.indexOf(note), 1) }); }

note is passed in from the EventEmitter in the note-item component