- In addition to managing state, we can also
perform traditional actions like adding, deleting,
or modifying records.
So, let's take a look at how we would
delete data in our Firebase application,
and take a look at one of the reasons why
Firebase is so awesome.
So, to do that, all we need to do is
modify this handle delete method.
We're still using this store based function here,
this is an action that we created.
So we'll modify it,
and all we need to do is access from our database,
which is the object that we created in our db.js file.
We will ask Firebase to look for
the collection that we called "songs,"
and from there we are going to ask for the document...
that is going to come in from our payload,
and the delete method that we get from Firebase
requires us to pass along the id of our document.
So, we're going to retrieve
the document id from the payload,
remember that payload comes from the list of songs.
When we click on the delete button,
we pass along the song information.
So, we just need to get the id of the song that we passed,
and then once we have that id, then we can
ask Firebase to execute the delete method,
and that's really all you need to do,
there are different methods for modifying
and adding records into Firebase,
but this is one of the easiest ones.
Let's do a bit of clean up as well.
We no longer need this computed property...
And we also don't need mapState from Vuex as well.
Let's go ahead and save that
and take a look at our application.
Nothing will really look like it changed,
but now when we delete a record,
it should delete from our application.
Now, the difference here is that
you are actually removing a record from the app.
So, let's go ahead and delete a few more
so that we just have a few records in here,
and you'll notice that when I refresh the application,
the records that are deleted are now gone,
and this is even cooler when you consider
that if we pull up another copy of the application,
whether it is on a phone or some other browser,
then if we delete a record from one of these browsers,
you'll notice that the other browser
will automatically update.
So, Firebase gives you much more
then just access to a database,
it manages changes to that database
from multiple users at the same time.
It's one of the reasons it's quickly become
a great choice for web developers.