Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 7cedf6f

Browse files
CaerusKaruThomasBurleson
authored andcommitted
fix(breakpoints): add global provider for BreakPointRegistry
* Fix issue with breakpoints not activating because the new breakpoints token is emptied when BreakPointRegistry is injected again
1 parent 84ca5c3 commit 7cedf6f

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import {InjectionToken, Optional, SkipSelf} from '@angular/core';
9+
10+
import {BreakPointRegistry} from './break-point-registry';
11+
import {BreakPoint} from './break-point';
12+
import {BREAKPOINTS} from './break-points-token';
13+
14+
/**
15+
* Ensure a single global service provider
16+
*/
17+
export function BREAKPOINT_REGISTRY_PROVIDER_FACTORY(parentRegistry: BreakPointRegistry,
18+
breakpoints: BreakPoint[]) {
19+
return parentRegistry || new BreakPointRegistry(breakpoints);
20+
}
21+
22+
23+
/**
24+
* Export provider that uses a global service factory (above)
25+
*/
26+
export const BREAKPOINT_REGISTRY_PROVIDER = {
27+
provide: BreakPointRegistry,
28+
deps: [
29+
[new Optional(), new SkipSelf(), BreakPointRegistry],
30+
<InjectionToken<BreakPoint[]>>BREAKPOINTS,
31+
],
32+
useFactory: BREAKPOINT_REGISTRY_PROVIDER_FACTORY
33+
};

src/lib/core/module.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import {NgModule} from '@angular/core';
99

1010
import {MediaMonitor} from './media-monitor/media-monitor';
11-
import {BreakPointRegistry} from './breakpoints/break-point-registry';
12-
11+
import {BREAKPOINT_REGISTRY_PROVIDER} from './breakpoints/break-point-registry-provider';
1312
import {OBSERVABLE_MEDIA_PROVIDER} from './observable-media/observable-media-provider';
1413
import {BREAKPOINTS_PROVIDER} from './breakpoints/break-points-provider';
1514
import {MATCH_MEDIA_PROVIDER} from './match-media/match-media-provider';
@@ -25,11 +24,11 @@ import {STYLESHEET_MAP_PROVIDER} from './stylesheet-map/stylesheet-map-provider'
2524

2625
@NgModule({
2726
providers: [
28-
BREAKPOINTS_PROVIDER, // Supports developer overrides of list of known breakpoints
29-
BreakPointRegistry, // Registry of known/used BreakPoint(s)
30-
MATCH_MEDIA_PROVIDER, // Low-level service to publish observables w/ window.matchMedia()
31-
MediaMonitor, // MediaQuery monitor service observes all known breakpoints
32-
OBSERVABLE_MEDIA_PROVIDER, // easy subscription injectable `media$` matchMedia observable]
27+
BREAKPOINTS_PROVIDER, // Supports developer overrides of list of known breakpoints
28+
BREAKPOINT_REGISTRY_PROVIDER, // Registry of known/used BreakPoint(s)
29+
MATCH_MEDIA_PROVIDER, // Low-level service to publish observables w/ window.matchMedia()
30+
MediaMonitor, // MediaQuery monitor service observes all known breakpoints
31+
OBSERVABLE_MEDIA_PROVIDER, // easy subscription injectable `media$` matchMedia observable]
3332
STYLESHEET_MAP_PROVIDER,
3433
StyleUtils,
3534
BROWSER_PROVIDER,

0 commit comments

Comments
 (0)