11import { ApplicationRef , Injectable , NgZone } from '@angular/core' ;
2- import { Unsubscribe } from 'redux' ;
2+ import { AnyAction , StoreEnhancer , Unsubscribe } from 'redux' ;
3+ import { EnhancerOptions } from 'redux-devtools-extension' ;
34import { NgRedux } from './ng-redux' ;
45
5- declare const window : any ;
6- const environment : any = typeof window !== 'undefined' ? window : { } ;
6+ export interface ReduxDevTools {
7+ ( options : EnhancerOptions ) : StoreEnhancer < any > ;
8+ listen : (
9+ onMessage : ( message : AnyAction ) => void ,
10+ instanceId ?: string ,
11+ ) => void ;
12+ }
13+
14+ interface WindowWithReduxDevTools extends Window {
15+ __REDUX_DEVTOOLS_EXTENSION__ ?: ReduxDevTools ;
16+ devToolsExtension ?: ReduxDevTools ;
17+ }
18+
19+ const environment : WindowWithReduxDevTools = ( typeof window !== 'undefined'
20+ ? window
21+ : { } ) as WindowWithReduxDevTools ;
722
823/**
924 * An angular-2-ified version of the Redux DevTools chrome extension.
@@ -22,14 +37,14 @@ export class DevToolsExtension {
2237 * format as described here:
2338 * [zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md]
2439 */
25- enhancer = ( options ?: object ) => {
40+ enhancer = ( options ?: EnhancerOptions ) => {
2641 let subscription : Unsubscribe ;
2742 if ( ! this . isEnabled ( ) ) {
2843 return null ;
2944 }
3045
3146 // Make sure changes from dev tools update angular's view.
32- environment . devToolsExtension . listen ( ( { type } : any ) => {
47+ this . getDevTools ( ) ! . listen ( ( { type } ) => {
3348 if ( type === 'START' ) {
3449 subscription = this . ngRedux . subscribe ( ( ) => {
3550 if ( ! NgZone . isInAngularZone ( ) ) {
@@ -41,11 +56,18 @@ export class DevToolsExtension {
4156 }
4257 } ) ;
4358
44- return environment . devToolsExtension ( options ) ;
59+ return this . getDevTools ( ) ! ( options || { } ) ;
4560 } ;
4661
4762 /**
4863 * Returns true if the extension is installed and enabled.
4964 */
50- isEnabled = ( ) => environment && environment . devToolsExtension ;
65+ isEnabled = ( ) => ! ! this . getDevTools ( ) ;
66+
67+ /**
68+ * Returns the redux devtools enhancer.
69+ */
70+ getDevTools = ( ) =>
71+ environment &&
72+ ( environment . __REDUX_DEVTOOLS_EXTENSION__ || environment . devToolsExtension ) ;
5173}
0 commit comments