Skip to content

Commit

Permalink
feat: add new devtools window prop name (#58)
Browse files Browse the repository at this point in the history
Adds support for the new '__REDUX_DEVTOOLS_EXTENSION__' window property
  • Loading branch information
wtho authored and smithad15 committed May 4, 2019
1 parent ae52528 commit 55b15a6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
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
36 changes: 29 additions & 7 deletions packages/store/src/components/dev-tools.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
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 : {};
export interface ReduxDevTools {
(options: EnhancerOptions): StoreEnhancer<any>;
listen: (
onMessage: (message: AnyAction) => void,
instanceId?: string,
) => void;
}

interface WindowWithReduxDevTools extends Window {
__REDUX_DEVTOOLS_EXTENSION__?: ReduxDevTools;
devToolsExtension?: ReduxDevTools;
}

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

/**
* An angular-2-ified version of the Redux DevTools chrome extension.
Expand All @@ -22,14 +37,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) => {
this.getDevTools()!.listen(({ type }) => {
if (type === 'START') {
subscription = this.ngRedux.subscribe(() => {
if (!NgZone.isInAngularZone()) {
Expand All @@ -41,11 +56,18 @@ export class DevToolsExtension {
}
});

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

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

/**
* Returns the redux devtools enhancer.
*/
getDevTools = () =>
environment &&
(environment.__REDUX_DEVTOOLS_EXTENSION__ || environment.devToolsExtension);
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8661,6 +8661,11 @@ redent@^2.0.0:
indent-string "^3.0.0"
strip-indent "^2.0.0"

redux-devtools-extension@^2.13.7:
version "2.13.7"
resolved "https://registry.yarnpkg.com/redux-devtools-extension/-/redux-devtools-extension-2.13.7.tgz#14bd7a1a7c8bee7f397beb1116fd16fc9633b752"
integrity sha512-F2GlWMWxCTJGRjJ+GSZcGDcVAj6Pbf77FKb4C9S8eni5Eah6UBGNwxNj8K1MTtmItdZH1Wx+EvIifHN2KKcQrw==

[email protected]:
version "2.10.2"
resolved "https://registry.yarnpkg.com/redux-logger/-/redux-logger-2.10.2.tgz#3c5a5f0a6f32577c1deadf6655f257f82c6c3937"
Expand Down

0 comments on commit 55b15a6

Please sign in to comment.