GithubHelp home page GithubHelp logo

Comments (10)

vip30 avatar vip30 commented on July 1, 2024 2
declare module 'idle-vue' {
  import Vue, { PluginFunction } from 'vue'
  export interface IdleVueUseOptions {
    events?: string[]
    eventEmitter?: any
    idleTime?: number
    keepTracking?: boolean
    moduleName?: string
    startAtIdle?: boolean
    store?: any
  }
  module "vue/types/vue" {
    interface Vue {
      isAppIdle: boolean
    }
  }
 // In case you want to vue.extend format
  module "vue/types/options" {
    interface ComponentOptions<V extends Vue> {
      onIdle?: () => void
      onActive?: () => void
    }
  }
  export function install(): PluginFunction<IdleVueUseOptions>
}

And here is the index.d.ts

from idle-vue.

vip30 avatar vip30 commented on July 1, 2024 1

FYI, you need to register the hooks before all of your codes.
Can you please try if it work or not?
As the above solutions is related to auto-suggestion on IDE only, it will not affect the real implementation in your code, if it still doesn't work I guess you may need to take a look on your store ?

// main.ts (Top)
import './class-component-hooks.ts'

// class-component-hooks.ts
Component.registerHooks([
'onIdle',
'onActive'
])

And if you want to use it in decorator format, I suggest you give it a try
https://github.com/vip30/vue-plugin-helper-decorator
My code as following:

// main.ts
Vue.use(IdleVue, {
  eventEmitter: new Vue(),
  keepTracking: true,
  idleTime: 180000
})

// xxx.vue
@Component({})
export default class App extends Vue {
  @OnActive()
  public callItWhenActive() {
     console.log('active')
  }
}

from idle-vue.

vip30 avatar vip30 commented on July 1, 2024
Vue.use(IdleVue, {
  eventEmitter: new Vue(),
  store,
  idleTime: 500
})
// class-component-hooks.js
Component.registerHooks([
  'onIdle',
  'onActive'
])
// Use either watch
@Watch('isAppIdle')
public onIdle() {
  console.log('Idle')
}

// or hooks
public onActive() {
  console.log('Active')
}

This is work for me (using vue-class-component)

from idle-vue.

maciz84 avatar maciz84 commented on July 1, 2024

Thank you so much for this

from idle-vue.

maciz84 avatar maciz84 commented on July 1, 2024

Just to confirm, i can use either the index.d.ts or the Vue class component one? Or are they meant to be put together?

from idle-vue.

vip30 avatar vip30 commented on July 1, 2024

You need to use that together
D.ts is for the type declaration (so it can pass the compile and so the intellisense in Ide will work)
And the vue class component is the real implmentation

from idle-vue.

maciz84 avatar maciz84 commented on July 1, 2024

This works perfectly. Thank you so much for your help

from idle-vue.

Luciden avatar Luciden commented on July 1, 2024

Can you tell my what I might be doing wrong? Here's my Main.ts
I added idle-vue.d.ts to my src directory root with the contents of your index.d.ts

No errors, nothing happens. isAppIdle is undefined.

`
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import { store } from './store/store';
import * as IdleVue from 'idle-vue';
import Component from 'vue-class-component';

Vue.config.productionTip = false;

// Setup idle-vue
Vue.use(IdleVue, {
eventEmitter: new Vue(),
store,
idleTime: 500
});

Component.registerHooks([
'onIdle',
'onActive'
])

new Vue({
el: '#app',
router,
store,
components: { App },
onIdle() {
console.log('Idle')
},
onActive() {
console.log('Active')
},
template: '',
});`

from idle-vue.

Luciden avatar Luciden commented on July 1, 2024

Cool, I'll check it out. We wrote Window.SetTimeout version in the meantime. We need a warning followed by a log out. I suppose I could add a timeout to OnIdle()

from idle-vue.

vip30 avatar vip30 commented on July 1, 2024

#34

from idle-vue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.