Skip to content

Update devtools window prop name #58

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

Merged
merged 9 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
1 change: 1 addition & 0 deletions packages/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"rxjs": "^6.0.0"
},
"devDependencies": {
"redux-devtools-extension": "^2.13.7",
"typedoc": "0.11.1",
"typedoc-plugin-sourcefile-url": "1.0.3"
},
Expand Down
27 changes: 20 additions & 7 deletions packages/store/src/components/dev-tools.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
// tslint:disable:no-implicit-dependencies
import { ApplicationRef, Injectable, NgZone } from '@angular/core';
import { Unsubscribe } from 'redux';
import { AnyAction, StoreEnhancer, Unsubscribe } from 'redux';
import { EnhancerOptions } from 'redux-devtools-extension';
import { NgRedux } from './ng-redux';

declare const window: any;
const environment: any = typeof window !== 'undefined' ? window : {};
interface WindowWithReduxDevTools extends Window {
__REDUX_DEVTOOLS_EXTENSION__?: {
(options: EnhancerOptions): StoreEnhancer<any>;
listen: (
onMessage: (message: AnyAction) => void,
instanceId?: string,
) => void;
};
}

const environment: WindowWithReduxDevTools = (typeof window !== 'undefined'
? window
: {}) as WindowWithReduxDevTools;

/**
* An angular-2-ified version of the Redux DevTools chrome extension.
Expand All @@ -22,14 +35,14 @@ export class DevToolsExtension {
* format as described here:
* [zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md]
*/
enhancer = (options?: object) => {
enhancer = (options?: EnhancerOptions) => {
let subscription: Unsubscribe;
if (!this.isEnabled()) {
return null;
}

// Make sure changes from dev tools update angular's view.
environment.devToolsExtension.listen(({ type }: any) => {
environment.__REDUX_DEVTOOLS_EXTENSION__!.listen(({ type }) => {
if (type === 'START') {
subscription = this.ngRedux.subscribe(() => {
if (!NgZone.isInAngularZone()) {
Expand All @@ -41,11 +54,11 @@ export class DevToolsExtension {
}
});

return environment.devToolsExtension(options);
return environment.__REDUX_DEVTOOLS_EXTENSION__!(options || {});
};

/**
* Returns true if the extension is installed and enabled.
*/
isEnabled = () => environment && environment.devToolsExtension;
isEnabled = () => environment && environment.__REDUX_DEVTOOLS_EXTENSION__;
}