Skip to content
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

Update devtools window prop name #58

Merged
merged 9 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
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==

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