Skip to content

Commit

Permalink
fix(InterruptSource): attach outside Angular
Browse files Browse the repository at this point in the history
  • Loading branch information
sliekens committed Mar 27, 2018
1 parent d626e43 commit c94fc9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 12 additions & 4 deletions modules/core/src/interruptsource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {EventEmitter} from '@angular/core';
import { EventEmitter } from '@angular/core';

import {InterruptArgs} from './interruptargs';
import { InterruptArgs } from './interruptargs';

/*
* A base for classes that act as a source for interrupts.
Expand All @@ -11,13 +11,21 @@ export abstract class InterruptSource {
public onInterrupt: EventEmitter<InterruptArgs> = new EventEmitter<InterruptArgs>();

constructor(
protected attachFn?: (source: InterruptSource) => void,
protected detachFn?: (source: InterruptSource) => void) {}
protected attachFn?: (source: InterruptSource) => void,
protected detachFn?: (source: InterruptSource) => void) { }

/*
* Attaches to the specified events on the specified source.
*/
attach(): void {
// If the current zone is the 'angular' zone (a.k.a. NgZone) then re-enter this method in its parent zone
// The parent zone is usually the '<root>' zone but it can also be 'long-stack-trace-zone' in debug mode
// In tests, the current zone is typically a 'ProxyZone' created by async/fakeAsync (from @angular/core/testing)
if (Zone.current.get('isAngularZone') === true) {
Zone.current.parent.run(() => this.attach());
return;
}

if (!this.isAttached && this.attachFn) {
this.attachFn(this);
}
Expand Down
3 changes: 2 additions & 1 deletion modules/tsconfig.es5.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"dom"
],
"types": [
"jasmine"
"jasmine",
"zone.js"
],
"paths": {
"@ng-idle/core": ["./core"]
Expand Down

0 comments on commit c94fc9a

Please sign in to comment.