-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(LazyMapsAPILoader): provide shortcut
Now, you can use a shortcut to configure the LazyMapsAPILoader: Before: ```typescript bootstrap(AppComponent, [ ANGULAR2_GOOGLE_MAPS_PROVIDERS, provide(LazyMapsAPILoaderConfig, {useFactory: () => { let config = new LazyMapsAPILoaderConfig(); config.apiKey = 'mykey'; return config; }}) ]) ``` After: ```typescript import {provide} from 'angular2/core'; import {provideLazyMapsAPILoaderConfig} from 'angular2-google-maps/core'; bootstrap(AppComponent, [ GOOGLE_MAPS_PROVIDERS, provideLazyMapsAPILoaderConfig({ apiKey: 'myKey' }) ]) ``` Closes #388 Closes #420
- Loading branch information
1 parent
c5d5744
commit 997aa80
Showing
5 changed files
with
142 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import {Provider} from '@angular/core'; | ||
import {provide} from '@angular/core'; | ||
|
||
import {LazyMapsAPILoader} from './services/maps-api-loader/lazy-maps-api-loader'; | ||
import {MapsAPILoader} from './services/maps-api-loader/maps-api-loader'; | ||
|
||
import {BROWSER_GLOBALS_PROVIDERS} from './utils/browser-globals'; | ||
|
||
// main modules | ||
export * from './directives'; | ||
export * from './services'; | ||
export * from './events'; | ||
|
||
export const GOOGLE_MAPS_PROVIDERS: any[] = [ | ||
new Provider(MapsAPILoader, {useClass: LazyMapsAPILoader}), | ||
...BROWSER_GLOBALS_PROVIDERS, | ||
provide(MapsAPILoader, {useClass: LazyMapsAPILoader}), | ||
]; |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export {GoogleMapsAPIWrapper} from './services/google-maps-api-wrapper'; | ||
export {InfoWindowManager} from './services/info-window-manager'; | ||
export {GoogleMapsScriptProtocol, LazyMapsAPILoader, LazyMapsAPILoaderConfig} from './services/maps-api-loader/lazy-maps-api-loader'; | ||
export {GoogleMapsScriptProtocol, LazyMapsAPILoader, LazyMapsAPILoaderConfig, LazyMapsAPILoaderConfigLiteral, provideLazyMapsAPILoaderConfig} from './services/maps-api-loader/lazy-maps-api-loader'; | ||
export {MapsAPILoader} from './services/maps-api-loader/maps-api-loader'; | ||
export {NoOpMapsAPILoader} from './services/maps-api-loader/noop-maps-api-loader'; | ||
export {MarkerManager} from './services/marker-manager'; |
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,4 @@ | ||
import {Provider, provide} from '@angular/core'; | ||
|
||
export const BROWSER_GLOBALS_PROVIDERS: Provider[] = | ||
[provide(Window, {useValue: window}), provide(Document, {useValue: document})]; |
41 changes: 41 additions & 0 deletions
41
test/services/maps-api-loader/lazy-maps-api-loader.spec.ts
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,41 @@ | ||
import {provide} from '@angular/core'; | ||
import {beforeEachProviders, describe, expect, inject, it} from '@angular/core/testing'; | ||
|
||
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'; | ||
|
||
export function main() { | ||
describe('Service: LazyMapsAPILoader', () => { | ||
beforeEachProviders(() => { | ||
return [ | ||
provide(MapsAPILoader, {useClass: LazyMapsAPILoader}), provide(Window, {useValue: {}}), | ||
provide( | ||
Document, {useValue: jasmine.createSpyObj<Document>('Document', ['createElement'])}) | ||
]; | ||
}); | ||
|
||
it('should create the default script URL', | ||
inject([MapsAPILoader, Document, Window], (loader: LazyMapsAPILoader, doc: Document) => { | ||
interface Script { | ||
src?: string; | ||
async?: boolean; | ||
defer?: boolean; | ||
type?: string; | ||
} | ||
const scriptElem: Script = {}; | ||
(<jasmine.Spy>doc.createElement).and.returnValue(scriptElem); | ||
doc.body = jasmine.createSpyObj('body', ['appendChild']); | ||
|
||
loader.load(); | ||
expect(doc.createElement).toHaveBeenCalled(); | ||
expect(scriptElem.type).toEqual('text/javascript'); | ||
expect(scriptElem.async).toEqual(true); | ||
expect(scriptElem.defer).toEqual(true); | ||
expect(scriptElem.src).toBeDefined(); | ||
expect(scriptElem.src).toContain('https://maps.googleapis.com/maps/api/js'); | ||
expect(scriptElem.src).toContain('v=3'); | ||
expect(scriptElem.src).toContain('callback=angular2GoogleMapsLazyMapsAPILoader'); | ||
expect(doc.body.appendChild).toHaveBeenCalledWith(scriptElem); | ||
})); | ||
}); | ||
} |