refactor(upgrade): clean up some types
This commit is contained in:
parent
a0b06befb6
commit
44b50427d9
|
@ -50,7 +50,7 @@ export interface IRootScopeService {
|
||||||
$destroy(): any;
|
$destroy(): any;
|
||||||
$apply(exp?: Ng1Expression): any;
|
$apply(exp?: Ng1Expression): any;
|
||||||
$digest(): any;
|
$digest(): any;
|
||||||
$evalAsync(): any;
|
$evalAsync(exp: Ng1Expression, locals?: any): void;
|
||||||
$on(event: string, fn?: (event?: any, ...args: any[]) => void): Function;
|
$on(event: string, fn?: (event?: any, ...args: any[]) => void): Function;
|
||||||
$$childTail: IScope;
|
$$childTail: IScope;
|
||||||
$$childHead: IScope;
|
$$childHead: IScope;
|
||||||
|
@ -101,7 +101,10 @@ export interface IComponent {
|
||||||
templateUrl?: string|Function;
|
templateUrl?: string|Function;
|
||||||
transclude?: DirectiveTranscludeProperty;
|
transclude?: DirectiveTranscludeProperty;
|
||||||
}
|
}
|
||||||
export interface IAttributes { $observe(attr: string, fn: (v: string) => void): void; }
|
export interface IAttributes {
|
||||||
|
$observe(attr: string, fn: (v: string) => void): void;
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
export interface ITranscludeFunction {
|
export interface ITranscludeFunction {
|
||||||
// If the scope is provided, then the cloneAttachFn must be as well.
|
// If the scope is provided, then the cloneAttachFn must be as well.
|
||||||
(scope: IScope, cloneAttachFn: ICloneAttachFunction): IAugmentedJQuery;
|
(scope: IScope, cloneAttachFn: ICloneAttachFunction): IAugmentedJQuery;
|
||||||
|
@ -135,7 +138,10 @@ export interface IProvideService {
|
||||||
decorator(token: Ng1Token, factory: IInjectable): void;
|
decorator(token: Ng1Token, factory: IInjectable): void;
|
||||||
}
|
}
|
||||||
export interface IParseService { (expression: string): ICompiledExpression; }
|
export interface IParseService { (expression: string): ICompiledExpression; }
|
||||||
export interface ICompiledExpression { assign(context: any, value: any): any; }
|
export interface ICompiledExpression {
|
||||||
|
(context: any, locals: any): any;
|
||||||
|
assign?: (context: any, value: any) => any;
|
||||||
|
}
|
||||||
export interface IHttpBackendService {
|
export interface IHttpBackendService {
|
||||||
(method: string, url: string, post?: any, callback?: Function, headers?: any, timeout?: number,
|
(method: string, url: string, post?: any, callback?: Function, headers?: any, timeout?: number,
|
||||||
withCredentials?: boolean): void;
|
withCredentials?: boolean): void;
|
||||||
|
@ -211,8 +217,8 @@ function noNg() {
|
||||||
|
|
||||||
|
|
||||||
let angular: {
|
let angular: {
|
||||||
bootstrap: (e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig) =>
|
bootstrap: (e: Element, modules: (string | IInjectable)[], config?: IAngularBootstrapConfig) =>
|
||||||
void,
|
IInjectorService,
|
||||||
module: (prefix: string, dependencies?: string[]) => IModule,
|
module: (prefix: string, dependencies?: string[]) => IModule,
|
||||||
element: (e: Element | string) => IAugmentedJQuery,
|
element: (e: Element | string) => IAugmentedJQuery,
|
||||||
version: {major: number},
|
version: {major: number},
|
||||||
|
@ -256,16 +262,16 @@ export function getAngularLib(): any {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const bootstrap =
|
export const bootstrap =
|
||||||
(e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig): void =>
|
(e: Element, modules: (string | IInjectable)[], config?: IAngularBootstrapConfig) =>
|
||||||
angular.bootstrap(e, modules, config);
|
angular.bootstrap(e, modules, config);
|
||||||
|
|
||||||
export const module = (prefix: string, dependencies?: string[]): IModule =>
|
export const module = (prefix: string, dependencies?: string[]) =>
|
||||||
angular.module(prefix, dependencies);
|
angular.module(prefix, dependencies);
|
||||||
|
|
||||||
export const element = (e: Element | string): IAugmentedJQuery => angular.element(e);
|
export const element = (e: Element | string) => angular.element(e);
|
||||||
|
|
||||||
export const resumeBootstrap = (): void => angular.resumeBootstrap();
|
export const resumeBootstrap = () => angular.resumeBootstrap();
|
||||||
|
|
||||||
export const getTestability = (e: Element): ITestabilityService => angular.getTestability(e);
|
export const getTestability = (e: Element) => angular.getTestability(e);
|
||||||
|
|
||||||
export const version = angular.version;
|
export const version = angular.version;
|
||||||
|
|
|
@ -69,7 +69,7 @@ export class DowngradeComponentAdapter {
|
||||||
const inputs = this.componentFactory.inputs || [];
|
const inputs = this.componentFactory.inputs || [];
|
||||||
for (let i = 0; i < inputs.length; i++) {
|
for (let i = 0; i < inputs.length; i++) {
|
||||||
const input = new PropertyBinding(inputs[i].propName, inputs[i].templateName);
|
const input = new PropertyBinding(inputs[i].propName, inputs[i].templateName);
|
||||||
let expr: any /** TODO #9100 */ = null;
|
let expr: string|null = null;
|
||||||
|
|
||||||
if (attrs.hasOwnProperty(input.attr)) {
|
if (attrs.hasOwnProperty(input.attr)) {
|
||||||
const observeFn = (prop => {
|
const observeFn = (prop => {
|
||||||
|
@ -91,20 +91,20 @@ export class DowngradeComponentAdapter {
|
||||||
// Use `$watch()` (in addition to `$observe()`) in order to initialize the input in time
|
// Use `$watch()` (in addition to `$observe()`) in order to initialize the input in time
|
||||||
// for `ngOnChanges()`. This is necessary if we are already in a `$digest`, which means that
|
// for `ngOnChanges()`. This is necessary if we are already in a `$digest`, which means that
|
||||||
// `ngOnChanges()` (which is called by a watcher) will run before the `$observe()` callback.
|
// `ngOnChanges()` (which is called by a watcher) will run before the `$observe()` callback.
|
||||||
let unwatch: any = this.componentScope.$watch(() => {
|
let unwatch: Function|null = this.componentScope.$watch(() => {
|
||||||
unwatch('');
|
unwatch !();
|
||||||
unwatch = null;
|
unwatch = null;
|
||||||
observeFn((attrs as any)[input.attr]);
|
observeFn(attrs[input.attr]);
|
||||||
});
|
});
|
||||||
|
|
||||||
} else if (attrs.hasOwnProperty(input.bindAttr)) {
|
} else if (attrs.hasOwnProperty(input.bindAttr)) {
|
||||||
expr = (attrs as any /** TODO #9100 */)[input.bindAttr];
|
expr = attrs[input.bindAttr];
|
||||||
} else if (attrs.hasOwnProperty(input.bracketAttr)) {
|
} else if (attrs.hasOwnProperty(input.bracketAttr)) {
|
||||||
expr = (attrs as any /** TODO #9100 */)[input.bracketAttr];
|
expr = attrs[input.bracketAttr];
|
||||||
} else if (attrs.hasOwnProperty(input.bindonAttr)) {
|
} else if (attrs.hasOwnProperty(input.bindonAttr)) {
|
||||||
expr = (attrs as any /** TODO #9100 */)[input.bindonAttr];
|
expr = attrs[input.bindonAttr];
|
||||||
} else if (attrs.hasOwnProperty(input.bracketParenAttr)) {
|
} else if (attrs.hasOwnProperty(input.bracketParenAttr)) {
|
||||||
expr = (attrs as any /** TODO #9100 */)[input.bracketParenAttr];
|
expr = attrs[input.bracketParenAttr];
|
||||||
}
|
}
|
||||||
if (expr != null) {
|
if (expr != null) {
|
||||||
const watchFn =
|
const watchFn =
|
||||||
|
@ -132,24 +132,22 @@ export class DowngradeComponentAdapter {
|
||||||
const outputs = this.componentFactory.outputs || [];
|
const outputs = this.componentFactory.outputs || [];
|
||||||
for (let j = 0; j < outputs.length; j++) {
|
for (let j = 0; j < outputs.length; j++) {
|
||||||
const output = new PropertyBinding(outputs[j].propName, outputs[j].templateName);
|
const output = new PropertyBinding(outputs[j].propName, outputs[j].templateName);
|
||||||
let expr: any /** TODO #9100 */ = null;
|
let expr: string|null = null;
|
||||||
let assignExpr = false;
|
let assignExpr = false;
|
||||||
|
|
||||||
const bindonAttr =
|
const bindonAttr = output.bindonAttr.substring(0, output.bindonAttr.length - 6);
|
||||||
output.bindonAttr ? output.bindonAttr.substring(0, output.bindonAttr.length - 6) : null;
|
const bracketParenAttr =
|
||||||
const bracketParenAttr = output.bracketParenAttr ?
|
`[(${output.bracketParenAttr.substring(2, output.bracketParenAttr.length - 8)})]`;
|
||||||
`[(${output.bracketParenAttr.substring(2, output.bracketParenAttr.length - 8)})]` :
|
|
||||||
null;
|
|
||||||
|
|
||||||
if (attrs.hasOwnProperty(output.onAttr)) {
|
if (attrs.hasOwnProperty(output.onAttr)) {
|
||||||
expr = (attrs as any /** TODO #9100 */)[output.onAttr];
|
expr = attrs[output.onAttr];
|
||||||
} else if (attrs.hasOwnProperty(output.parenAttr)) {
|
} else if (attrs.hasOwnProperty(output.parenAttr)) {
|
||||||
expr = (attrs as any /** TODO #9100 */)[output.parenAttr];
|
expr = attrs[output.parenAttr];
|
||||||
} else if (attrs.hasOwnProperty(bindonAttr !)) {
|
} else if (attrs.hasOwnProperty(bindonAttr)) {
|
||||||
expr = (attrs as any /** TODO #9100 */)[bindonAttr !];
|
expr = attrs[bindonAttr];
|
||||||
assignExpr = true;
|
assignExpr = true;
|
||||||
} else if (attrs.hasOwnProperty(bracketParenAttr !)) {
|
} else if (attrs.hasOwnProperty(bracketParenAttr)) {
|
||||||
expr = (attrs as any /** TODO #9100 */)[bracketParenAttr !];
|
expr = attrs[bracketParenAttr];
|
||||||
assignExpr = true;
|
assignExpr = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,10 +160,8 @@ export class DowngradeComponentAdapter {
|
||||||
const emitter = this.component[output.prop] as EventEmitter<any>;
|
const emitter = this.component[output.prop] as EventEmitter<any>;
|
||||||
if (emitter) {
|
if (emitter) {
|
||||||
emitter.subscribe({
|
emitter.subscribe({
|
||||||
next: assignExpr ?
|
next: assignExpr ? (v: any) => setter !(this.scope, v) :
|
||||||
((setter: any) => (v: any /** TODO #9100 */) => setter(this.scope, v))(setter) :
|
(v: any) => getter(this.scope, {'$event': v})
|
||||||
((getter: any) => (v: any /** TODO #9100 */) =>
|
|
||||||
getter(this.scope, {'$event': v}))(getter)
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
|
@ -247,7 +247,7 @@ export class UpgradeModule {
|
||||||
const upgradeModule = angular.module(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));
|
const upgradeModule = angular.module(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));
|
||||||
|
|
||||||
// Make sure resumeBootstrap() only exists if the current bootstrap is deferred
|
// Make sure resumeBootstrap() only exists if the current bootstrap is deferred
|
||||||
const windowAngular = (window as any /** TODO #???? */)['angular'];
|
const windowAngular = (window as any)['angular'];
|
||||||
windowAngular.resumeBootstrap = undefined;
|
windowAngular.resumeBootstrap = undefined;
|
||||||
|
|
||||||
// Bootstrap the AngularJS application inside our zone
|
// Bootstrap the AngularJS application inside our zone
|
||||||
|
@ -280,4 +280,4 @@ class NgAdapterInjector implements Injector {
|
||||||
|
|
||||||
return this.modInjector.get(token, notFoundValue);
|
return this.modInjector.get(token, notFoundValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ export function main() {
|
||||||
afterEach(() => destroyPlatform());
|
afterEach(() => destroyPlatform());
|
||||||
|
|
||||||
it('should interleave scope and component expressions', async(() => {
|
it('should interleave scope and component expressions', async(() => {
|
||||||
const log: any[] /** TODO #9100 */ = [];
|
const log: string[] = [];
|
||||||
const l = (value: any /** TODO #9100 */) => {
|
const l = (value: string) => {
|
||||||
log.push(value);
|
log.push(value);
|
||||||
return value + ';';
|
return value + ';';
|
||||||
};
|
};
|
||||||
|
@ -46,8 +46,7 @@ export function main() {
|
||||||
template: `{{l('2A')}}<ng1a></ng1a>{{l('2B')}}<ng1b></ng1b>{{l('2C')}}`
|
template: `{{l('2A')}}<ng1a></ng1a>{{l('2B')}}<ng1b></ng1b>{{l('2C')}}`
|
||||||
})
|
})
|
||||||
class Ng2Component {
|
class Ng2Component {
|
||||||
l: (value: any) => string;
|
l = l;
|
||||||
constructor() { this.l = l; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
@ -63,7 +62,7 @@ export function main() {
|
||||||
.directive('ng1a', () => ({template: '{{ l(\'ng1a\') }}'}))
|
.directive('ng1a', () => ({template: '{{ l(\'ng1a\') }}'}))
|
||||||
.directive('ng1b', () => ({template: '{{ l(\'ng1b\') }}'}))
|
.directive('ng1b', () => ({template: '{{ l(\'ng1b\') }}'}))
|
||||||
.directive('ng2', downgradeComponent({component: Ng2Component}))
|
.directive('ng2', downgradeComponent({component: Ng2Component}))
|
||||||
.run(($rootScope: any /** TODO #9100 */) => {
|
.run(($rootScope: angular.IRootScopeService) => {
|
||||||
$rootScope.l = l;
|
$rootScope.l = l;
|
||||||
$rootScope.reset = () => log.length = 0;
|
$rootScope.reset = () => log.length = 0;
|
||||||
});
|
});
|
||||||
|
@ -72,7 +71,6 @@ export function main() {
|
||||||
html('<div>{{reset(); l(\'1A\');}}<ng2>{{l(\'1B\')}}</ng2>{{l(\'1C\')}}</div>');
|
html('<div>{{reset(); l(\'1A\');}}<ng2>{{l(\'1B\')}}</ng2>{{l(\'1C\')}}</div>');
|
||||||
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then((upgrade) => {
|
bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then((upgrade) => {
|
||||||
expect(document.body.textContent).toEqual('1A;2A;ng1a;2B;ng1b;2C;1C;');
|
expect(document.body.textContent).toEqual('1A;2A;ng1a;2B;ng1b;2C;1C;');
|
||||||
// https://github.com/angular/angular.js/issues/12983
|
|
||||||
expect(log).toEqual(['1A', '1C', '2A', '2B', '2C', 'ng1a', 'ng1b']);
|
expect(log).toEqual(['1A', '1C', '2A', '2B', '2C', 'ng1a', 'ng1b']);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
@ -88,7 +86,7 @@ export function main() {
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-child',
|
selector: 'my-child',
|
||||||
template: '<div>{{valueFromPromise}}',
|
template: '<div>{{ valueFromPromise }}</div>',
|
||||||
})
|
})
|
||||||
class ChildComponent {
|
class ChildComponent {
|
||||||
valueFromPromise: number;
|
valueFromPromise: number;
|
||||||
|
|
|
@ -18,7 +18,7 @@ export function bootstrap(
|
||||||
// We bootstrap the Angular module first; then when it is ready (async)
|
// We bootstrap the Angular module first; then when it is ready (async)
|
||||||
// We bootstrap the AngularJS module on the bootstrap element
|
// We bootstrap the AngularJS module on the bootstrap element
|
||||||
return platform.bootstrapModule(Ng2Module).then(ref => {
|
return platform.bootstrapModule(Ng2Module).then(ref => {
|
||||||
const upgrade = ref.injector.get(UpgradeModule) as UpgradeModule;
|
const upgrade = ref.injector.get<UpgradeModule>(UpgradeModule);
|
||||||
upgrade.bootstrap(element, [ng1Module.name]);
|
upgrade.bootstrap(element, [ng1Module.name]);
|
||||||
return upgrade;
|
return upgrade;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue