mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(platform-browser-dynamic): unused RESOURCE_CACHE_PROVIDER API has been removed (#54875)
BREAKING CHANGE: No longer used `RESOURCE_CACHE_PROVIDER` APIs have been removed. PR Close #54875
This commit is contained in:
parent
55c3932f5e
commit
eb20c1a8b1
4 changed files with 1 additions and 131 deletions
|
|
@ -8,7 +8,6 @@ import { Compiler } from '@angular/core';
|
|||
import { CompilerFactory } from '@angular/core';
|
||||
import { CompilerOptions } from '@angular/core';
|
||||
import { PlatformRef } from '@angular/core';
|
||||
import { Provider } from '@angular/core';
|
||||
import { StaticProvider } from '@angular/core';
|
||||
import { Version } from '@angular/core';
|
||||
|
||||
|
|
@ -21,9 +20,6 @@ export class JitCompilerFactory implements CompilerFactory {
|
|||
// @public (undocumented)
|
||||
export const platformBrowserDynamic: (extraProviders?: StaticProvider[] | undefined) => PlatformRef;
|
||||
|
||||
// @public @deprecated (undocumented)
|
||||
export const RESOURCE_CACHE_PROVIDER: Provider[];
|
||||
|
||||
// @public (undocumented)
|
||||
export const VERSION: Version;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,27 +6,15 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ResourceLoader} from '@angular/compiler';
|
||||
import {createPlatformFactory, Provider} from '@angular/core';
|
||||
import {createPlatformFactory} from '@angular/core';
|
||||
|
||||
import {platformCoreDynamic} from './platform_core_dynamic';
|
||||
import {INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS} from './platform_providers';
|
||||
import {CachedResourceLoader} from './resource_loader/resource_loader_cache';
|
||||
|
||||
export * from './private_export';
|
||||
export {VERSION} from './version';
|
||||
export {JitCompilerFactory} from './compiler_factory';
|
||||
|
||||
/**
|
||||
* @publicApi
|
||||
*
|
||||
* @deprecated This was previously necessary in some cases to test AOT-compiled components with View
|
||||
* Engine, but is no longer since Ivy.
|
||||
|
||||
*/
|
||||
export const RESOURCE_CACHE_PROVIDER: Provider[] =
|
||||
[{provide: ResourceLoader, useClass: CachedResourceLoader, deps: []}];
|
||||
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ResourceLoader} from '@angular/compiler';
|
||||
import {ɵglobal as global} from '@angular/core';
|
||||
|
||||
/**
|
||||
* An implementation of ResourceLoader that uses a template cache to avoid doing an actual
|
||||
* ResourceLoader.
|
||||
*
|
||||
* The template cache needs to be built and loaded into window.$templateCache
|
||||
* via a separate mechanism.
|
||||
*
|
||||
* @publicApi
|
||||
*
|
||||
* @deprecated This was previously necessary in some cases to test AOT-compiled components with View
|
||||
* Engine, but is no longer since Ivy.
|
||||
*/
|
||||
export class CachedResourceLoader extends ResourceLoader {
|
||||
private _cache: {[url: string]: string};
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._cache = (<any>global).$templateCache;
|
||||
if (this._cache == null) {
|
||||
throw new Error('CachedResourceLoader: Template cache was not found in $templateCache.');
|
||||
}
|
||||
}
|
||||
|
||||
override get(url: string): Promise<string> {
|
||||
if (this._cache.hasOwnProperty(url)) {
|
||||
return Promise.resolve(this._cache[url]);
|
||||
} else {
|
||||
return <Promise<any>>Promise.reject(
|
||||
'CachedResourceLoader: Did not find cached template for ' + url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
import {fakeAsync, TestBed, tick, waitForAsync} from '@angular/core/testing';
|
||||
import {CachedResourceLoader} from '@angular/platform-browser-dynamic/src/resource_loader/resource_loader_cache';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
if (isBrowser) {
|
||||
// TODO(alxhub): Resource loading works very differently in Ivy.
|
||||
xdescribe('CachedResourceLoader', () => {
|
||||
let resourceLoader: CachedResourceLoader;
|
||||
|
||||
function createCachedResourceLoader(): CachedResourceLoader {
|
||||
setTemplateCache({'test.html': '<div>Hello</div>'});
|
||||
return new CachedResourceLoader();
|
||||
}
|
||||
|
||||
it('should throw exception if $templateCache is not found', () => {
|
||||
setTemplateCache(null);
|
||||
expect(() => {
|
||||
resourceLoader = new CachedResourceLoader();
|
||||
}).toThrowError('CachedResourceLoader: Template cache was not found in $templateCache.');
|
||||
});
|
||||
|
||||
it('should resolve the Promise with the cached file content on success', waitForAsync(() => {
|
||||
resourceLoader = createCachedResourceLoader();
|
||||
resourceLoader.get('test.html').then((text) => {
|
||||
expect(text).toBe('<div>Hello</div>');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should reject the Promise on failure', waitForAsync(() => {
|
||||
resourceLoader = createCachedResourceLoader();
|
||||
resourceLoader.get('unknown.html').then(() => {
|
||||
throw new Error('Not expected to succeed.');
|
||||
}, () => {/* success */});
|
||||
}));
|
||||
|
||||
it('should allow fakeAsync Tests to load components with templateUrl synchronously',
|
||||
fakeAsync(() => {
|
||||
const loader = createCachedResourceLoader();
|
||||
@Component({selector: 'test-cmp', templateUrl: 'test.html'})
|
||||
class TestComponent {
|
||||
}
|
||||
|
||||
// resolveComponentResources(url => loader.get(url));
|
||||
tick();
|
||||
|
||||
TestBed.configureTestingModule({declarations: [TestComponent]});
|
||||
TestBed.compileComponents();
|
||||
tick();
|
||||
|
||||
const fixture = TestBed.createComponent(TestComponent);
|
||||
|
||||
// This should initialize the fixture.
|
||||
tick();
|
||||
|
||||
expect(fixture.debugElement.children[0].nativeElement).toHaveText('Hello');
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
function setTemplateCache(cache: {}|null): void {
|
||||
(<any>window).$templateCache = cache;
|
||||
}
|
||||
Loading…
Reference in a new issue