ng-idle-observable-interrupt-source
TypeScript icon, indicating that this package has built-in type declarations

0.9.0 • Public • Published

ng-idle-observable-interrupt-source

An add-on for @ng-idle/core to use RxJS Observables as idle interrupt sources

Installation

npm install ng-idle-observable-interrupt-source

Usage

import ObservableInterruptSource from 'ng-idle-observable-interrupt-source';
import { Idle, DEFAULT_INTERRUPTSOURCES } from '@ng-idle/core';
import { Store } from '@ngrx/store';

const idleSeconds = 300;
const logoutWarningSeconds = 30;

export class SomeComponent implements OnInit, OnDestroy {
  constructor(
    private idle: Idle,
    store: Store,
    someService: SomeService,
  ) {
    this.idle.setIdle(idleSeconds);
    this.idle.onIdleStart(() => store.dispatch(showLogoutWarningDialog()));

    this.idle.setTimeout(logoutWarningSeconds);
    this.idle.onTimeout(() => store.dispatch(logout()));

    const someServiceInterruptSource = new ObservableInterruptSource(someService.observable$);
    this.idle.setInterrupts([...DEFAULT_INTERRUPTSOURCES, someServiceInterruptSource]);
  }

  ngOnInit() {
    this.idle.watch();
  }

  ngOnDestroy() {
    this.idle.clearInterrupts();
    this.idle.stop();
  }
}

Package Sidebar

Install

npm i ng-idle-observable-interrupt-source

Weekly Downloads

88

Version

0.9.0

License

MIT

Unpacked Size

4.44 kB

Total Files

7

Last publish

Collaborators

  • svicalifornia