-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store-devtools): add provideStoreDevtools function (#3537)
Closes #3527
- Loading branch information
1 parent
511b7cf
commit 6b0db4e
Showing
4 changed files
with
91 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
import { | ||
DevtoolsExtension, | ||
REDUX_DEVTOOLS_EXTENSION, | ||
ReduxDevtoolsExtension, | ||
} from './extension'; | ||
import { DevtoolsDispatcher } from './devtools-dispatcher'; | ||
import { | ||
createConfig, | ||
INITIAL_OPTIONS, | ||
noMonitor, | ||
STORE_DEVTOOLS_CONFIG, | ||
StoreDevtoolsConfig, | ||
StoreDevtoolsOptions, | ||
} from './config'; | ||
import { | ||
EnvironmentProviders, | ||
ReducerManagerDispatcher, | ||
StateObservable, | ||
} from '@ngrx/store'; | ||
import { createStateObservable } from './instrument'; | ||
import { StoreDevtools } from './devtools'; | ||
|
||
export const IS_EXTENSION_OR_MONITOR_PRESENT = new InjectionToken<boolean>( | ||
'@ngrx/store-devtools Is Devtools Extension or Monitor Present' | ||
); | ||
|
||
export function createIsExtensionOrMonitorPresent( | ||
extension: ReduxDevtoolsExtension | null, | ||
config: StoreDevtoolsConfig | ||
) { | ||
return Boolean(extension) || config.monitor !== noMonitor; | ||
} | ||
|
||
export function createReduxDevtoolsExtension() { | ||
const extensionKey = '__REDUX_DEVTOOLS_EXTENSION__'; | ||
|
||
if ( | ||
typeof window === 'object' && | ||
typeof (window as any)[extensionKey] !== 'undefined' | ||
) { | ||
return (window as any)[extensionKey]; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
export function provideStoreDevtools( | ||
options: StoreDevtoolsOptions = {} | ||
): EnvironmentProviders { | ||
return { | ||
ɵproviders: [ | ||
DevtoolsExtension, | ||
DevtoolsDispatcher, | ||
StoreDevtools, | ||
{ | ||
provide: INITIAL_OPTIONS, | ||
useValue: options, | ||
}, | ||
{ | ||
provide: IS_EXTENSION_OR_MONITOR_PRESENT, | ||
deps: [REDUX_DEVTOOLS_EXTENSION, STORE_DEVTOOLS_CONFIG], | ||
useFactory: createIsExtensionOrMonitorPresent, | ||
}, | ||
{ | ||
provide: REDUX_DEVTOOLS_EXTENSION, | ||
useFactory: createReduxDevtoolsExtension, | ||
}, | ||
{ | ||
provide: STORE_DEVTOOLS_CONFIG, | ||
deps: [INITIAL_OPTIONS], | ||
useFactory: createConfig, | ||
}, | ||
{ | ||
provide: StateObservable, | ||
deps: [StoreDevtools], | ||
useFactory: createStateObservable, | ||
}, | ||
{ | ||
provide: ReducerManagerDispatcher, | ||
useExisting: DevtoolsDispatcher, | ||
}, | ||
], | ||
}; | ||
} |