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

feat(compiler): Add implementation for a XHR that uses a template cache to load template files. #7940

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
7 participants
@vikerman
Contributor

vikerman commented Apr 6, 2016

  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format
  • Tests for the changes have been added (for bug fixes / features)
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Feature - Provide a XHR implementation that uses a template cache to avoid actually making an XHR. Exports CACHED_TEMPLATE_PROVIDER through angular2/platform/browser and angular2/platform/testing/browser which can be used by applications and tests to use the cached XHR implementation.
  • What is the current behavior? (You can also link to an open issue here)
    #4051
  • What is the new behavior (if this is a feature change)?
    If the application or test uses the cached XHR implementation by setting up the provider for XHR it will use the template cache instead of making an actual XHR. This can be useful for writing fakeAsync tests.
  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
    No
  • Other information:

Useful for avoiding doing an actual XHR during testing.
Part of the solution for #4051 (Other part is a Karma plugin that will create the template cache).

@vikerman

This comment has been minimized.

Contributor

vikerman commented Apr 6, 2016

@lacolaco

This comment has been minimized.

Contributor

lacolaco commented Apr 7, 2016

Is this just for testing?
I want a similar system for application to preload (programmatical load) component's template refered by templateUrl.
It is like ng-template of ng1.

@ericmartinezr

This comment has been minimized.

Contributor

ericmartinezr commented Apr 7, 2016

@laco0416 that's what the new compiller will do, will convert the templateUrl's in files intead of requesting them

@lacolaco

This comment has been minimized.

Contributor

lacolaco commented Apr 7, 2016

@ericmartinezr sounds good. thx!

constructor() {
super();
this._cache = (<any>window).$templateCache;

This comment has been minimized.

@tbosch

tbosch Apr 7, 2016

Member

Don't use window but the global variable exported from angular2/src/facade/lang.ts

This comment has been minimized.

@vikerman

vikerman Apr 7, 2016

Contributor

Done.

.toThrowErrorWith('CachedXHR: Template cache was not found in $templateCache.');
});
it('should resolve the Promise with the cached file content on success',

This comment has been minimized.

@tbosch

tbosch Apr 7, 2016

Member

Could you also add a test that creates a component via fakeAsync and the cache?

This comment has been minimized.

@vikerman

vikerman Apr 7, 2016

Contributor

Done.

feat(compiler): Add an implementation for XHR that uses a template ca…
…che to load template files.

Useful for avoiding doing an actual XHR during testing.
Part of the solution for #4051 (Other part is a Karma plugin that will create the template cache).
@mary-poppins

This comment has been minimized.

mary-poppins commented Apr 8, 2016

Merging PR #7940 on behalf of @alxhub to branch presubmit-alxhub-pr-7940.

@mhevery mhevery closed this in a596b88 Apr 8, 2016

mirco312312 added a commit to mirco312312/angular that referenced this pull request Apr 10, 2016

feat(compiler): Add an implementation for XHR that uses a template ca…
…che to load template files.

Useful for avoiding doing an actual XHR during testing.
Part of the solution for angular#4051 (Other part is a Karma plugin that will create the template cache).

Closes angular#7940
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment