malekim / v-idle

A Vue.js plugin to detect idle/non-active users
https://malekim.github.io/v-idle/
MIT License
70 stars 8 forks source link

Emit Vue event when a new event is received #30

Closed roberto910907 closed 4 months ago

roberto910907 commented 2 years ago

It'd be great if we can listen to the events registered in the component here. In that way, we can do certain actions when the values are restarted eg. close information modals, etc.

Maybe something like this:

window.addEventListener(this.events[i], function() {
     this.$emit('event-triggered', this.events[i]);
     this.clearTimer();
})

Then we can do something like this:

<v-idle @event-triggered="closeModal($event)"/>
......

closeModal(event) {
      if (event === 'mousemove') {
          // execute my actions (close information modal)
      }
}

@malekim Is there any other way to achieve the same with this library?

malekim commented 2 years ago

Looks reasonable, I added this to my todo list.

roberto910907 commented 2 years ago

@malekim thanks! That'd be great because I was thinking of automatically hiding the countdown modal whenever you move the mouse(no need to click over a button, if you're already interacting with the page I'm assuming you're back). I can try to open a PR this weekend :)

deidyomega commented 4 months ago

@roberto910907 You can now do this using refresh callback

<v-idle @refresh="onrefresh" />

function onrefresh() { console.log("user did something") }
malekim commented 4 months ago

I extended refresh event with additional data. There is an example in the documentation.