Check out a free preview of the full Vuex for Intermediate Vue 2 Developers course

The "Action Plugin Exercise" Lesson is part of the full, Vuex for Intermediate Vue 2 Developers course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to modify the previous plugin to use the subscribeAction handler. The handler is used in Vuex because it calls every dispatched action and receive the action descriptor and current store state as arguments.


Transcript from the "Action Plugin Exercise" Lesson

>> The next piece of what's useful is to look at other parts of what we can peek into, because I mentioned that you can peek into the store as a whole. So we looked at state and we looked at mutation. And oftentimes it's useful to look at mutations because that's when state actually changed.

But sometimes you might wanna know when an action happens as well, because sometimes an action happens even though state doesn't change. You want to know what happened, and why, maybe why. And so what you can do is, you can actually call subscribe action. So store has a method call subscribe action, and it takes in an action as the first argument.

So, just to go back to show you what the previous code was, because I think it's useful to see sort of a side by side. Previously, when you're looking at a mutation, you would just do store.subscribe to get a mutation, and then you use the mutation appropriately. But in our instance, we are accessing the action.

And to access action, you can't do store.subscribe, you have to do store.subscribe action. And that will give you the specific action, and very similar to mutation, you get access to the type as well as the payload. So you can use them however you choose, very similar to what we did before.

And there are properties that are accessible on the action. So the next exercise that we'll work on, is to modify our subscribe, to use a subscribe action, so that we can see how exactly that can be useful. We'll keep, essentially when I say modify, I mean just add subscribe action, so you don't have to remove what you had before.

We're just gonna add something separate.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now