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

fix(LazyMapsAPILoader): use OpaqueTokens for globs #441

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export * from './services';
export * from './events';

export const GOOGLE_MAPS_PROVIDERS: any[] = [
...BROWSER_GLOBALS_PROVIDERS,
BROWSER_GLOBALS_PROVIDERS,
provide(MapsAPILoader, {useClass: LazyMapsAPILoader}),
];
8 changes: 6 additions & 2 deletions src/core/services/maps-api-loader/lazy-maps-api-loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {Injectable, Optional, Provider, provide} from '@angular/core';
import {Inject, Injectable, Optional, Provider, provide} from '@angular/core';

import {DOCUMENT_GLOBAL, WINDOW_GLOBAL} from '../../utils/browser-globals';

import {MapsAPILoader} from './maps-api-loader';

Expand Down Expand Up @@ -95,7 +97,9 @@ export class LazyMapsAPILoader extends MapsAPILoader {
private _window: Window;
private _document: Document;

constructor(@Optional() config: LazyMapsAPILoaderConfig, w: Window, d: Document) {
constructor(
@Optional() config: LazyMapsAPILoaderConfig, @Inject(WINDOW_GLOBAL) w: Window,
@Inject(DOCUMENT_GLOBAL) d: Document) {
super();
this._config = config || DEFAULT_CONFIGURATION;
this._window = w;
Expand Down
7 changes: 5 additions & 2 deletions src/core/utils/browser-globals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {Provider, provide} from '@angular/core';
import {OpaqueToken, Provider, provide} from '@angular/core';

export const WINDOW_GLOBAL = new OpaqueToken('angular2-google-maps window_global');
export const DOCUMENT_GLOBAL = new OpaqueToken('angular2-google-maps document_global');

export const BROWSER_GLOBALS_PROVIDERS: Provider[] =
[provide(Window, {useValue: window}), provide(Document, {useValue: document})];
[provide(WINDOW_GLOBAL, {useValue: window}), provide(DOCUMENT_GLOBAL, {useValue: document})];
10 changes: 6 additions & 4 deletions test/services/maps-api-loader/lazy-maps-api-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import {beforeEachProviders, describe, expect, inject, it} from '@angular/core/t

import {LazyMapsAPILoader} from '../../../src/core/services/maps-api-loader/lazy-maps-api-loader';
import {MapsAPILoader} from '../../../src/core/services/maps-api-loader/maps-api-loader';
import {DOCUMENT_GLOBAL, WINDOW_GLOBAL} from '../../../src/core/utils/browser-globals';

export function main() {
describe('Service: LazyMapsAPILoader', () => {
beforeEachProviders(() => {
return [
provide(MapsAPILoader, {useClass: LazyMapsAPILoader}), provide(Window, {useValue: {}}),
provide(
Document, {useValue: jasmine.createSpyObj<Document>('Document', ['createElement'])})
provide(MapsAPILoader, {useClass: LazyMapsAPILoader}),
provide(WINDOW_GLOBAL, {useValue: {}}), provide(DOCUMENT_GLOBAL, {
useValue: jasmine.createSpyObj<Document>('Document', ['createElement'])
})
];
});

it('should create the default script URL',
inject([MapsAPILoader, Document, Window], (loader: LazyMapsAPILoader, doc: Document) => {
inject([MapsAPILoader, DOCUMENT_GLOBAL], (loader: LazyMapsAPILoader, doc: Document) => {
interface Script {
src?: string;
async?: boolean;
Expand Down