refactor(render): move services to right location
core/compiler/events -> render/dom/events core/compiler/url_resolver -> services/url_resolver core/compiler/xhr/* -> services/*
This commit is contained in:
@ -16,7 +16,7 @@ import {Template} from '../annotations/template';
|
||||
import {ShadowDomStrategy} from './shadow_dom_strategy';
|
||||
import {CompileStep} from './pipeline/compile_step';
|
||||
import {ComponentUrlMapper} from './component_url_mapper';
|
||||
import {UrlResolver} from './url_resolver';
|
||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||
import {CssProcessor} from './css_processor';
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {Compiler} from './compiler';
|
||||
import {ShadowDomStrategy} from './shadow_dom_strategy';
|
||||
import {EventManager} from 'angular2/src/core/events/event_manager';
|
||||
import {EventManager} from 'angular2/src/render/dom/events/event_manager';
|
||||
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
|
||||
import {Component} from 'angular2/src/core/annotations/annotations';
|
||||
import {PrivateComponentLocation} from './private_component_location';
|
||||
|
@ -3,7 +3,7 @@ import {NgElement} from 'angular2/src/core/dom/element';
|
||||
import * as viewModule from './view';
|
||||
import * as eiModule from './element_injector';
|
||||
import {ShadowDomStrategy} from './shadow_dom_strategy';
|
||||
import {EventManager} from 'angular2/src/core/events/event_manager';
|
||||
import {EventManager} from 'angular2/src/render/dom/events/event_manager';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {Type} from 'angular2/src/facade/lang';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {Injectable} from 'angular2/di';
|
||||
import {XHR} from 'angular2/src/core/compiler/xhr/xhr';
|
||||
import {XHR} from 'angular2/src/services/xhr';
|
||||
import {StyleUrlResolver} from 'angular2/src/core/compiler/style_url_resolver';
|
||||
import {UrlResolver} from 'angular2/src/core/compiler/url_resolver';
|
||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
import {Injectable} from 'angular2/di';
|
||||
import {RegExp, RegExpWrapper, StringWrapper} from 'angular2/src/facade/lang';
|
||||
import {UrlResolver} from './url_resolver';
|
||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||
|
||||
/**
|
||||
* Rewrites URLs by resolving '@import' and 'url()' URLs from the given base URL.
|
||||
|
@ -3,11 +3,11 @@ import {isBlank, isPresent, BaseException, stringify} from 'angular2/src/facade/
|
||||
import {Map, MapWrapper, StringMapWrapper, StringMap} from 'angular2/src/facade/collection';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
|
||||
import {XHR} from './xhr/xhr';
|
||||
import {XHR} from 'angular2/src/services/xhr';
|
||||
|
||||
import {Template} from 'angular2/src/core/annotations/template';
|
||||
|
||||
import {UrlResolver} from './url_resolver';
|
||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||
|
||||
/**
|
||||
* Strategy to load component templates.
|
||||
|
@ -1,38 +0,0 @@
|
||||
import {Injectable} from 'angular2/di';
|
||||
import {isPresent, isBlank, RegExpWrapper, BaseException} from 'angular2/src/facade/lang';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
|
||||
@Injectable()
|
||||
export class UrlResolver {
|
||||
static a;
|
||||
|
||||
constructor() {
|
||||
if (isBlank(UrlResolver.a)) {
|
||||
UrlResolver.a = DOM.createElement('a');
|
||||
}
|
||||
}
|
||||
|
||||
resolve(baseUrl: string, url: string): string {
|
||||
if (isBlank(baseUrl)) {
|
||||
DOM.resolveAndSetHref(UrlResolver.a, url, null);
|
||||
return DOM.getHref(UrlResolver.a);
|
||||
}
|
||||
|
||||
if (isBlank(url) || url == '') return baseUrl;
|
||||
|
||||
if (url[0] == '/') {
|
||||
throw new BaseException(`Could not resolve the url ${url} from ${baseUrl}`);
|
||||
}
|
||||
|
||||
var m = RegExpWrapper.firstMatch(_schemeRe, url);
|
||||
|
||||
if (isPresent(m[1])) {
|
||||
return url;
|
||||
}
|
||||
|
||||
DOM.resolveAndSetHref(UrlResolver.a, baseUrl, url);
|
||||
return DOM.getHref(UrlResolver.a);
|
||||
}
|
||||
}
|
||||
|
||||
var _schemeRe = RegExpWrapper.create('^([^:/?#]+:)?');
|
14
modules/angular2/src/core/compiler/view.js
vendored
14
modules/angular2/src/core/compiler/view.js
vendored
@ -16,7 +16,7 @@ import {LightDom} from './shadow_dom_emulation/light_dom';
|
||||
import {Content} from './shadow_dom_emulation/content_tag';
|
||||
import {ShadowDomStrategy} from './shadow_dom_strategy';
|
||||
import {ViewPool} from './view_pool';
|
||||
import {EventManager} from 'angular2/src/core/events/event_manager';
|
||||
import {EventManager} from 'angular2/src/render/dom/events/event_manager';
|
||||
|
||||
const NG_BINDING_CLASS = 'ng-binding';
|
||||
const NG_BINDING_CLASS_SELECTOR = '.ng-binding';
|
||||
@ -306,7 +306,7 @@ export class ProtoView {
|
||||
parentProtoView:ProtoView;
|
||||
_variableBindings:List;
|
||||
|
||||
_directiveMementosMap:Map;
|
||||
_directiveMementosMap:Map;
|
||||
_directiveMementos:List;
|
||||
|
||||
constructor(
|
||||
@ -486,7 +486,7 @@ export class ProtoView {
|
||||
ListWrapper.push(componentChildViews, childView);
|
||||
}
|
||||
lightDoms[binderIdx] = lightDom;
|
||||
|
||||
|
||||
var destLightDom = null;
|
||||
if (isPresent(binder.parent) && binder.distanceToParent === 1) {
|
||||
destLightDom = lightDoms[binder.parent.index];
|
||||
@ -574,7 +574,7 @@ export class ProtoView {
|
||||
|
||||
bindElement(parent:ElementBinder, distanceToParent:int, protoElementInjector:ProtoElementInjector,
|
||||
componentDirective:DirectiveMetadata = null, viewportDirective:DirectiveMetadata = null):ElementBinder {
|
||||
var elBinder = new ElementBinder(this.elementBinders.length, parent, distanceToParent,
|
||||
var elBinder = new ElementBinder(this.elementBinders.length, parent, distanceToParent,
|
||||
protoElementInjector, componentDirective, viewportDirective);
|
||||
ListWrapper.push(this.elementBinders, elBinder);
|
||||
return elBinder;
|
||||
@ -653,18 +653,18 @@ export class ProtoView {
|
||||
var directiveMemento = this._getDirectiveMemento(elementIndex, directiveIndex);
|
||||
ListWrapper.push(this.bindingRecords, new BindingRecord(expression, bindingMemento, directiveMemento));
|
||||
}
|
||||
|
||||
|
||||
_getDirectiveMemento(elementInjectorIndex:number, directiveIndex:number) {
|
||||
var id = elementInjectorIndex * 100 + directiveIndex;
|
||||
var protoElementInjector = this.elementBinders[elementInjectorIndex].protoElementInjector;
|
||||
|
||||
|
||||
if (!MapWrapper.contains(this._directiveMementosMap, id)) {
|
||||
var binding = protoElementInjector.getDirectiveBindingAtIndex(directiveIndex);
|
||||
MapWrapper.set(this._directiveMementosMap, id,
|
||||
new DirectiveMemento(elementInjectorIndex, directiveIndex,
|
||||
binding.callOnAllChangesDone, binding.callOnChange));
|
||||
}
|
||||
|
||||
|
||||
return MapWrapper.get(this._directiveMementosMap, id);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import {BaseException} from 'angular2/src/facade/lang';
|
||||
import {Injector} from 'angular2/di';
|
||||
import * as eiModule from 'angular2/src/core/compiler/element_injector';
|
||||
import {isPresent, isBlank} from 'angular2/src/facade/lang';
|
||||
import {EventManager} from 'angular2/src/core/events/event_manager';
|
||||
import {EventManager} from 'angular2/src/render/dom/events/event_manager';
|
||||
import {LightDom} from './shadow_dom_emulation/light_dom';
|
||||
|
||||
/**
|
||||
@ -88,7 +88,7 @@ export class ViewContainer {
|
||||
var newView = this.defaultProtoView.instantiate(this.hostElementInjector, this._eventManager);
|
||||
// insertion must come before hydration so that element injector trees are attached.
|
||||
this.insert(newView, atIndex);
|
||||
newView.hydrate(this.appInjector, this.hostElementInjector, this.hostLightDom,
|
||||
newView.hydrate(this.appInjector, this.hostElementInjector, this.hostLightDom,
|
||||
this.parentView.context, this.parentView.locals);
|
||||
|
||||
// new content tags might have appeared, we need to redistrubute.
|
||||
|
@ -1,7 +0,0 @@
|
||||
import {Promise} from 'angular2/src/facade/async';
|
||||
|
||||
export class XHR {
|
||||
get(url: string): Promise<string> {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:html';
|
||||
import 'package:angular2/di.dart';
|
||||
import './xhr.dart' show XHR;
|
||||
|
||||
@Injectable()
|
||||
class XHRImpl extends XHR {
|
||||
Future<String> get(String url) {
|
||||
return HttpRequest.request(url).then(
|
||||
(HttpRequest request) => request.responseText,
|
||||
onError: (Error e) => throw 'Failed to load $url'
|
||||
);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
import {Injectable} from 'angular2/di';
|
||||
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {XHR} from './xhr';
|
||||
|
||||
@Injectable()
|
||||
export class XHRImpl extends XHR {
|
||||
get(url: string): Promise<string> {
|
||||
var completer = PromiseWrapper.completer();
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'text';
|
||||
|
||||
xhr.onload = function() {
|
||||
var status = xhr.status;
|
||||
if (200 <= status && status <= 300) {
|
||||
completer.resolve(xhr.responseText);
|
||||
} else {
|
||||
completer.reject(`Failed to load ${url}`);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() {
|
||||
completer.reject(`Failed to load ${url}`);
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
return completer.promise;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user