Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/adding ability to reset idle #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
adding method to reset idle timer
Christopher Caldwell committed Oct 14, 2019
commit 4cddfdc23ade1b9ad04c0bd4cb3d7994b1625e76
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -77,6 +77,67 @@ const vm = new Vue({
</div>
```

### Methods

A build in method is extended through the use of the global mixin, allowing you to reset the idle timer from anywhere in your application.

#### Example
// assumes you are using the plugin method

```html
<template>
<div @click="resetIdleTimer">
Click to reset
</div>
</template>

<script>
export default {
methods: {
resetIdleTimer(){
this.$resetIdle() // stops timer, resets values to default, starts again
}
}
}
</script>
```

#### Use Cases

This can be handy when writing unit tests that rely on the idle timer being reset after an assertion.

```js
// using jest and vue test utils
import Vue from 'vue'
import IdleVue from 'idle-vue'
import { createLocalVue, shallowMount } from '@vue/test-utils'

const eventEmitter = new Vue()

const idleVueMock = localVue.use(IdleVue, {
eventEmitter,
idleTime: 1000 // 1/10th of a second
})
beforeEach(() => {
wrapper = shallowMount(App, {
// other plugins
idleVueMock
})
// resetting the timer before each test runs
wrapper.vm.$resetIdle()
})

describe('The idle timer doing what it\'s supposed to', () => {
it('Something happened after idle', done => {
setTimeout(() => {
const yourTestCase = 'something that happened because the timer ran out'
expect(yourTestCase).toBe(true)
done()
}, 1000)
})
})
```

### `isAppIdle`

The plug-in adds a computed value `isAppIdle` to every Vue object.
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -76,6 +76,13 @@ export default {
isAppIdle () {
return store && store.state[moduleName].isIdle
}
},
methods: {
$resetIdle(){
idle.stop()
idle.reset()
idle.start();
}
}
})
}