Skip to content

Commit

Permalink
fix(Devtools): Removed SHOULD_INSTRUMENT token used to eagerly inject…
Browse files Browse the repository at this point in the history
… providers (#57)

We were previously using the SHOULD_INSTRUMENT token to decide whether the instrumentation should occur due to AOT. Since this is no longer needed as NgModules can be conditionally included, this code that introduces eager providers can be removed
  • Loading branch information
brandonroberts authored and MikeRyanDev committed Jul 3, 2017
1 parent 1f67cb3 commit b90df34
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
2 changes: 0 additions & 2 deletions modules/store-devtools/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { InjectionToken, Type } from '@angular/core';
export interface StoreDevtoolsConfig {
maxAge: number | false;
monitor: ActionReducer<any, any>;
shouldInstrument: Type<boolean> | InjectionToken<boolean>;
}

export const STORE_DEVTOOLS_CONFIG = new InjectionToken<StoreDevtoolsConfig>('@ngrx/devtools Options');
export const INITIAL_OPTIONS = new InjectionToken<StoreDevtoolsConfig>('@ngrx/devtools Initial Config');
export const SHOULD_INSTRUMENT = new InjectionToken<boolean>('@ngrx/devtools Should Instrument');

export type StoreDevtoolsOptions
= Partial<StoreDevtoolsConfig>
Expand Down
2 changes: 1 addition & 1 deletion modules/store-devtools/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { StoreDevtoolsModule } from './instrument';
export { LiftedState } from './reducer';
export { StoreDevtools } from './devtools';
export { StoreDevtoolsConfig, StoreDevtoolsOptions, SHOULD_INSTRUMENT } from './config';
export { StoreDevtoolsConfig, StoreDevtoolsOptions } from './config';
27 changes: 6 additions & 21 deletions modules/store-devtools/src/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
INITIAL_REDUCERS,
REDUCER_FACTORY } from '@ngrx/store';
import { StoreDevtools, DevtoolsDispatcher } from './devtools';
import { StoreDevtoolsConfig, StoreDevtoolsOptions, STORE_DEVTOOLS_CONFIG, INITIAL_OPTIONS, SHOULD_INSTRUMENT } from './config';
import { StoreDevtoolsConfig, StoreDevtoolsOptions, STORE_DEVTOOLS_CONFIG, INITIAL_OPTIONS } from './config';
import { DevtoolsExtension, REDUX_DEVTOOLS_EXTENSION, ReduxDevtoolsExtension } from './extension';


Expand All @@ -40,12 +40,8 @@ export function createReduxDevtoolsExtension() {
}
}

export function createStateObservable(shouldInstrument: boolean, injector: Injector) {
return shouldInstrument ? injector.get(StoreDevtools).state : injector.get(State);
}

export function createReducerManagerDispatcher(shouldInstrument: boolean, injector: Injector) {
return shouldInstrument ? injector.get(DevtoolsDispatcher) : injector.get(ActionsSubject);
export function createStateObservable(devtools: StoreDevtools) {
return devtools.state;
}

export function noMonitor(): null {
Expand All @@ -55,8 +51,7 @@ export function noMonitor(): null {
export function createConfig(_options: StoreDevtoolsOptions): StoreDevtoolsConfig {
const DEFAULT_OPTIONS: StoreDevtoolsConfig = {
maxAge: false,
monitor: noMonitor,
shouldInstrument: IS_EXTENSION_OR_MONITOR_PRESENT,
monitor: noMonitor
};

let options = typeof _options === 'function' ? _options() : _options;
Expand All @@ -69,10 +64,6 @@ export function createConfig(_options: StoreDevtoolsOptions): StoreDevtoolsConfi
return config;
}

export function createShouldInstrument(injector: Injector, config: StoreDevtoolsConfig) {
return injector.get(config.shouldInstrument);
}

@NgModule({
imports: [
StoreModule
Expand Down Expand Up @@ -101,25 +92,19 @@ export class StoreDevtoolsModule {
provide: REDUX_DEVTOOLS_EXTENSION,
useFactory: createReduxDevtoolsExtension
},
{
provide: SHOULD_INSTRUMENT,
deps: [ Injector, STORE_DEVTOOLS_CONFIG ],
useFactory: createShouldInstrument
},
{
provide: STORE_DEVTOOLS_CONFIG,
deps: [ INITIAL_OPTIONS ],
useFactory: createConfig
},
{
provide: StateObservable,
deps: [ SHOULD_INSTRUMENT, Injector ],
deps: [ StoreDevtools ],
useFactory: createStateObservable
},
{
provide: ReducerManagerDispatcher,
deps: [ SHOULD_INSTRUMENT, Injector ],
useFactory: createReducerManagerDispatcher
useExisting: DevtoolsDispatcher
},
]
};
Expand Down
2 changes: 1 addition & 1 deletion modules/store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export { combineReducers, compose } from './utils';
export { ActionsSubject, INIT } from './actions_subject';
export { ReducerManager, ReducerObservable, ReducerManagerDispatcher, UPDATE } from './reducer_manager';
export { ScannedActionsSubject } from './scanned_actions_subject';
export { createSelector, createFeatureSelector } from './selector';
export { createSelector, createFeatureSelector, MemoizedSelector } from './selector';
export { State, StateObservable, reduceState } from './state';
export { INITIAL_STATE, REDUCER_FACTORY, INITIAL_REDUCERS, STORE_FEATURES } from './tokens';
export { StoreRootModule, StoreFeatureModule } from './store_module';

0 comments on commit b90df34

Please sign in to comment.